This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
PATCH: Fix read_leb128 in readelf for 64bit host
- From: "H. J. Lu" <hjl at lucon dot org>
- To: binutils at sources dot redhat dot com
- Date: Sat, 25 Dec 2004 16:42:29 -0800
- Subject: PATCH: Fix read_leb128 in readelf for 64bit host
read_leb128 in readelf assumes long == int == 32bit. It doesn't work
with 64bit host. Does this patch look right?
H.J.
---
2004-12-25 H.J. Lu <hongjiu.lu@intel.com>
* readelf.c (read_leb128): Support 64bit host.
--- binutils/readelf.c.leb 2004-12-10 14:20:22.000000000 -0800
+++ binutils/readelf.c 2004-12-25 16:16:54.615198445 -0800
@@ -6933,7 +6933,7 @@ read_leb128 (unsigned char *data, int *l
{
unsigned long int result = 0;
unsigned int num_read = 0;
- int shift = 0;
+ unsigned int shift = 0;
unsigned char byte;
do
@@ -6951,8 +6951,8 @@ read_leb128 (unsigned char *data, int *l
if (length_return != NULL)
*length_return = num_read;
- if (sign && (shift < 32) && (byte & 0x40))
- result |= -1 << shift;
+ if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
+ result |= -1L << shift;
return result;
}