This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
Re: [RFA] Fix buffer full test in remote.c
- From: Andrew Cagney <ac131313 at cygnus dot com>
- To: fnf at redhat dot com
- Cc: gdb-patches at sources dot redhat dot com
- Date: Sat, 09 Mar 2002 17:48:01 -0500
- Subject: Re: [RFA] Fix buffer full test in remote.c
- References: <200203080540.g285eAn14785@fred.ninemoons.com>
> To check when were are close to filling the buffer, we need to use the
> size of the allocated buffer, not the available buffer space after
> subtracting off all the packet overhead.
>
> Consider the case where get_memory_write_packet_size() returns 16.
> The allocated buffer will be 17 bytes. The X packet header will
> actually be around 9 bytes, which is subtracted from 16 to give 7
> bytes available for data. The loop will never execute because "p-buf"
> will be 9 after putting the header in the buf, and "max_buf_size-2"
> will be 7-2, or 5, and 9 is not less than 5. (These numbers may not
> be exact, but should point out the problem).
Ah! I don't think changing the test to use sizeof_buf (sizeof_buf - 2)
is correct. That will let GDB send down packets of size:
sizeof_buf - 2 + strlen ("#NN")
which I think overflows the max packet size (looking at my hand sketch,
by one character?).
I suspect a better way of fixing it is to change things to:
/* Subtract header overhead ... */
payload_size = max_buf_size - (...);
....
s/max_buf_size/payload_size/
....
/* Append the packet body. */
payload_start = p;
..... && (p - payload_start) < payload_size);
(if nothing else it gets rid of the overloaded use of max_buf_size).
Andrew