This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[commit] Fix up read_signed_leb128
- From: Daniel Jacobowitz <drow at false dot org>
- To: gdb-patches at sourceware dot org
- Date: Mon, 1 Aug 2005 00:08:35 -0400
- Subject: [commit] Fix up read_signed_leb128
H.J. Lu noticed last year that GDB's read_signed_leb128 couldn't handle
some 64-bit negative values even if they fit in the return type. I've
tested and committed this fix.
Of course it's not of any practical use: the rest of GDB probably
wouldn't cope well, but I didn't see any obviously problematic users of
this function. Still, it's a utility function - best to keep it
correct.
--
Daniel Jacobowitz
CodeSourcery, LLC
2005-08-01 Daniel Jacobowitz <dan@codesourcery.com>
* dwarf2-frame.c (read_signed_leb128): Handle values that do not
fit in 32 bits.
* dwarf2read.c (read_signed_leb128): Likewise.
Index: dwarf2-frame.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2-frame.c,v
retrieving revision 1.53
diff -u -p -r1.53 dwarf2-frame.c
--- dwarf2-frame.c 12 Jul 2005 13:06:54 -0000 1.53
+++ dwarf2-frame.c 1 Aug 2005 04:00:16 -0000
@@ -1105,8 +1105,8 @@ read_signed_leb128 (bfd *abfd, gdb_byte
}
while (byte & 0x80);
- if ((shift < 32) && (byte & 0x40))
- result |= -(1 << shift);
+ if (shift < 8 * sizeof (result) && (byte & 0x40))
+ result |= -(((LONGEST)1) << shift);
*bytes_read_ptr = num_read;
Index: dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.182
diff -u -p -r1.182 dwarf2read.c
--- dwarf2read.c 4 Jul 2005 13:29:10 -0000 1.182
+++ dwarf2read.c 1 Aug 2005 04:00:17 -0000
@@ -6032,12 +6032,11 @@ static long
read_signed_leb128 (bfd *abfd, char *buf, unsigned int *bytes_read_ptr)
{
long result;
- int i, shift, size, num_read;
+ int i, shift, num_read;
unsigned char byte;
result = 0;
shift = 0;
- size = 32;
num_read = 0;
i = 0;
while (1)
@@ -6052,10 +6051,8 @@ read_signed_leb128 (bfd *abfd, char *buf
break;
}
}
- if ((shift < size) && (byte & 0x40))
- {
- result |= -(1 << shift);
- }
+ if ((shift < 8 * sizeof (result)) && (byte & 0x40))
+ result |= -(((long)1) << shift);
*bytes_read_ptr = num_read;
return result;
}