aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcomex2016-11-15 22:00:01 -0500
committercomex2016-11-15 22:00:01 -0500
commit29c86ae6f5a4b44b1c5c7ee1e16366d8c44e33ea (patch)
treec5c1e2e40c489b3a40552fe5f3e0ffdd927e1812
parentI don't remember what this test is for (diff)
downloadsubstitute-29c86ae6f5a4b44b1c5c7ee1e16366d8c44e33ea.tar.gz
avoid UB
-rw-r--r--lib/darwin/read.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/darwin/read.c b/lib/darwin/read.c
index 2e5b746..a0a5d8e 100644
--- a/lib/darwin/read.c
+++ b/lib/darwin/read.c
@@ -9,11 +9,11 @@ bool read_leb128(void **ptr, void *end, bool is_signed, uint64_t *out) {
return false;
bit = *p++;
uint64_t k = bit & 0x7f;
- if (shift < sizeof(uint64_t) * 8)
+ if (shift < 64)
result |= k << shift;
shift += 7;
} while (bit & 0x80);
- if (is_signed && (bit & 0x40))
+ if (is_signed && (bit & 0x40) && shift < 64)
result |= ~((uint64_t) 0) << shift;
*ptr = p;
if (out)