aboutsummaryrefslogtreecommitdiff
path: root/include/llvm/Support/LEB128.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/llvm/Support/LEB128.h')
-rw-r--r--include/llvm/Support/LEB128.h15
1 files changed, 8 insertions, 7 deletions
diff --git a/include/llvm/Support/LEB128.h b/include/llvm/Support/LEB128.h
index 9feb07229225..a02b83ca9597 100644
--- a/include/llvm/Support/LEB128.h
+++ b/include/llvm/Support/LEB128.h
@@ -1,9 +1,8 @@
//===- llvm/Support/LEB128.h - [SU]LEB128 utility functions -----*- C++ -*-===//
//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
@@ -166,6 +165,8 @@ inline int64_t decodeSLEB128(const uint8_t *p, unsigned *n = nullptr,
int64_t Value = 0;
unsigned Shift = 0;
uint8_t Byte;
+ if (error)
+ *error = nullptr;
do {
if (end && p == end) {
if (error)
@@ -175,11 +176,11 @@ inline int64_t decodeSLEB128(const uint8_t *p, unsigned *n = nullptr,
return 0;
}
Byte = *p++;
- Value |= (int64_t(Byte & 0x7f) << Shift);
+ Value |= (uint64_t(Byte & 0x7f) << Shift);
Shift += 7;
} while (Byte >= 128);
- // Sign extend negative numbers.
- if (Byte & 0x40)
+ // Sign extend negative numbers if needed.
+ if (Shift < 64 && (Byte & 0x40))
Value |= (-1ULL) << Shift;
if (n)
*n = (unsigned)(p - orig_p);