This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA] Fix buffer full test in remote.c


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).

-Fred

  2002-03-07  Fred Fish  <fnf@redhat.com>

	* remote.c (remote_write_bytes): Use sizeof_buf to decide when we
	are close to filling the buffer, not max_buf_size.

Index: remote.c
===================================================================
RCS file: /cvs/src/src/gdb/remote.c,v
retrieving revision 1.77
diff -u -p -r1.77 remote.c
--- remote.c	2002/02/27 01:18:39	1.77
+++ remote.c	2002/03/08 05:32:51
@@ -3794,7 +3794,7 @@ remote_write_bytes (CORE_ADDR memaddr, c
 	 increasing byte addresses.  Only escape certain critical
 	 characters.  */
       for (nr_bytes = 0;
-	   (nr_bytes < todo) && (p - buf) < (max_buf_size - 2);
+	   (nr_bytes < todo) && (p - buf) < (sizeof_buf - 2);
 	   nr_bytes++)
 	{
 	  switch (myaddr[nr_bytes] & 0xff)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]