From 29c86ae6f5a4b44b1c5c7ee1e16366d8c44e33ea Mon Sep 17 00:00:00 2001 From: comex Date: Tue, 15 Nov 2016 22:00:01 -0500 Subject: avoid UB --- lib/darwin/read.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/darwin/read.c') 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) -- cgit v1.2.3