mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-03-04 05:31:51 +00:00
[Support] Fix the overflow bug in ULEB128 decoding.
Differential Revision: http://reviews.llvm.org/D5029 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216268 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
cc59c3f335
commit
4ef54c3f85
@ -82,7 +82,7 @@ inline uint64_t decodeULEB128(const uint8_t *p, unsigned *n = nullptr) {
|
||||
uint64_t Value = 0;
|
||||
unsigned Shift = 0;
|
||||
do {
|
||||
Value += (*p & 0x7f) << Shift;
|
||||
Value += uint64_t(*p & 0x7f) << Shift;
|
||||
Shift += 7;
|
||||
} while (*p++ >= 128);
|
||||
if (n)
|
||||
|
@ -106,6 +106,7 @@ TEST(LEB128Test, DecodeULEB128) {
|
||||
EXPECT_DECODE_ULEB128_EQ(0xffu, "\xff\x01");
|
||||
EXPECT_DECODE_ULEB128_EQ(0x100u, "\x80\x02");
|
||||
EXPECT_DECODE_ULEB128_EQ(0x101u, "\x81\x02");
|
||||
EXPECT_DECODE_ULEB128_EQ(4294975616ULL, "\x80\xc1\x80\x80\x10");
|
||||
|
||||
// Decode ULEB128 with extra padding bytes
|
||||
EXPECT_DECODE_ULEB128_EQ(0u, "\x80\x00");
|
||||
|
Loading…
x
Reference in New Issue
Block a user