diff options
author | Cary Coutant <ccoutant@google.com> | 2012-01-25 07:34:55 +0000 |
---|---|---|
committer | Cary Coutant <ccoutant@google.com> | 2012-01-25 07:34:55 +0000 |
commit | c2c7840a42aaab8354bb1997d141149d30316603 (patch) | |
tree | d9314a7c096f70d4c290eb753c80bf372498901d /gold/int_encoding.cc | |
parent | 21abe33a9bdebefa7f917bcc99e946eb464cc67f (diff) | |
download | fsf-binutils-gdb-c2c7840a42aaab8354bb1997d141149d30316603.zip fsf-binutils-gdb-c2c7840a42aaab8354bb1997d141149d30316603.tar.gz fsf-binutils-gdb-c2c7840a42aaab8354bb1997d141149d30316603.tar.bz2 |
* int_encoding.cc (read_unsigned_LEB_128): Replaced with inline
definition and ...
(read_unsigned_LEB_128_x): ... this new function.
(read_signed_LEB_128): Replaced with inline definition and ...
(read_signed_LEB_128_x): ... this new function.
* int_encoding.h (read_unsigned_LEB_128_x): New function.
(read_unsigned_LEB_128): Add inline definition.
(read_signed_LEB_128_x): New function.
(read_signed_LEB_128): Add inline definition.
* testsuite/Makefile.am (leb128_unittest): New unit test.
* testsuite/Makefile.in: Regenerate.
* testsuite/leb128_unittest.cc: New unit test.
Diffstat (limited to 'gold/int_encoding.cc')
-rw-r--r-- | gold/int_encoding.cc | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/gold/int_encoding.cc b/gold/int_encoding.cc index 6d635ac..7887477 100644 --- a/gold/int_encoding.cc +++ b/gold/int_encoding.cc @@ -32,19 +32,20 @@ namespace gold { // Read an unsigned LEB128 number. Each byte contains 7 bits of // information, plus one bit saying whether the number continues or -// not. +// not. BYTE contains the first byte of the number, and is guaranteed +// to have the continuation bit set. uint64_t -read_unsigned_LEB_128(const unsigned char* buffer, size_t* len) +read_unsigned_LEB_128_x(const unsigned char* buffer, size_t* len, + unsigned char byte) { - uint64_t result = 0; - size_t num_read = 0; - unsigned int shift = 0; - unsigned char byte; + uint64_t result = static_cast<uint64_t>(byte & 0x7f); + size_t num_read = 1; + unsigned int shift = 7; do { - if (num_read >= 64 / 7) + if (num_read > 64 / 7 + 1) { gold_warning(_("Unusually large LEB128 decoded, " "debug information may be corrupted")); @@ -64,18 +65,20 @@ read_unsigned_LEB_128(const unsigned char* buffer, size_t* len) // Read a signed LEB128 number. These are like regular LEB128 // numbers, except the last byte may have a sign bit set. +// BYTE contains the first byte of the number, and is guaranteed +// to have the continuation bit set. int64_t -read_signed_LEB_128(const unsigned char* buffer, size_t* len) +read_signed_LEB_128_x(const unsigned char* buffer, size_t* len, + unsigned char byte) { - int64_t result = 0; - int shift = 0; - size_t num_read = 0; - unsigned char byte; + int64_t result = static_cast<uint64_t>(byte & 0x7f); + int shift = 7; + size_t num_read = 1; do { - if (num_read >= 64 / 7) + if (num_read > 64 / 7 + 1) { gold_warning(_("Unusually large LEB128 decoded, " "debug information may be corrupted")); |