Skip to contentSkip to conversation

fix out-of-bounds error

PATCH New Grégoire Sutre 1 participant 1 message Mar 18, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix out-of-bounds error

I get the following warning on Debian GNU/Linux when compiling with -O2. This is with GCC 4.6.3.

$ CFLAGS='-O2' ./configure && make
...
gdb/cstub.c: In function 'grub_gdb_trap':
gdb/cstub.c:83:21: error: array subscript is above array bounds [-Werror=array-bounds]
cc1: all warnings being treated as errors
make[3]: *** [gdb/gdb_module-cstub.o] Error 1
make[3]: Leaving directory `/tmp/GRUB/trunk/grub-core'

Afaics, the out-of-bounds error is real, and the attached patch fixes it.

Grégoire

=== modified file 'grub-core/gdb/cstub.c'

gdb/cstub.c +1 -1
@@ -57,27 +57,27 @@ grub_gdb_getpacket (void)
 
   while (1)
     {
       /* Wait around for the start character, ignore all other
          characters.  */
       while ((ch = grub_serial_port_fetch (grub_gdb_port)) != '$');
 
     retry:
       checksum = 0;
       xmitcsum = -1;
       count = 0;
 
       /* Now read until a # or end of buffer is found.  */
-      while (count < GRUB_GDB_COMBUF_SIZE)
+      while (count < GRUB_GDB_COMBUF_SIZE - 1)
 	{
 	  do
 	    ch = grub_serial_port_fetch (grub_gdb_port);
 	  while (ch < 0);
 	  if (ch == '$')
 	    goto retry;
 	  if (ch == '#')
 	    break;
 	  checksum += ch;
 	  buffer[count] = ch;
 	  count = count + 1;
 	}
       buffer[count] = 0;