aboutsummaryrefslogtreecommitdiff
path: root/libdw/memory-access.h
diff options
context:
space:
mode:
Diffstat (limited to 'libdw/memory-access.h')
-rw-r--r--libdw/memory-access.h20
1 files changed, 13 insertions, 7 deletions
diff --git a/libdw/memory-access.h b/libdw/memory-access.h
index 16c8c851..6d79343c 100644
--- a/libdw/memory-access.h
+++ b/libdw/memory-access.h
@@ -64,7 +64,7 @@ __libdw_max_len_sleb128 (const unsigned char *addr, const unsigned char *end)
#define get_uleb128_step(var, addr, nth) \
do { \
unsigned char __b = *(addr)++; \
- (var) |= (typeof (var)) (__b & 0x7f) << ((nth) * 7); \
+ (var) |= (__typeof (var)) (__b & 0x7f) << ((nth) * 7); \
if (likely ((__b & 0x80) == 0)) \
return (var); \
} while (0)
@@ -72,13 +72,16 @@ __libdw_max_len_sleb128 (const unsigned char *addr, const unsigned char *end)
static inline uint64_t
__libdw_get_uleb128 (const unsigned char **addrp, const unsigned char *end)
{
+ const size_t max = __libdw_max_len_uleb128 (*addrp, end);
+ if (unlikely (max == 0))
+ return UINT64_MAX;
+
uint64_t acc = 0;
/* Unroll the first step to help the compiler optimize
for the common single-byte case. */
get_uleb128_step (acc, *addrp, 0);
- const size_t max = __libdw_max_len_uleb128 (*addrp - 1, end);
for (size_t i = 1; i < max; ++i)
get_uleb128_step (acc, *addrp, i);
/* Other implementations set VALUE to UINT_MAX in this
@@ -112,11 +115,11 @@ __libdw_get_uleb128_unchecked (const unsigned char **addrp)
#define get_sleb128_step(var, addr, nth) \
do { \
unsigned char __b = *(addr)++; \
- (var) |= (typeof (var)) (__b & 0x7f) << ((nth) * 7); \
+ (var) |= (__typeof (var)) (__b & 0x7f) << ((nth) * 7); \
if (likely ((__b & 0x80) == 0)) \
{ \
if ((__b & 0x40) != 0) \
- (var) |= - ((typeof (var)) 1 << (((nth) + 1) * 7)); \
+ (var) |= - ((__typeof (var)) 1 << (((nth) + 1) * 7)); \
return (var); \
} \
} while (0)
@@ -124,6 +127,10 @@ __libdw_get_uleb128_unchecked (const unsigned char **addrp)
static inline int64_t
__libdw_get_sleb128 (const unsigned char **addrp, const unsigned char *end)
{
+ const size_t max = __libdw_max_len_sleb128 (*addrp, end);
+ if (unlikely (max == 0))
+ return INT64_MAX;
+
/* Do the work in an unsigned type, but use implementation-defined
behavior to cast to signed on return. This avoids some undefined
behavior when shifting. */
@@ -133,7 +140,6 @@ __libdw_get_sleb128 (const unsigned char **addrp, const unsigned char *end)
for the common single-byte case. */
get_sleb128_step (acc, *addrp, 0);
- const size_t max = __libdw_max_len_sleb128 (*addrp - 1, end);
for (size_t i = 1; i < max; ++i)
get_sleb128_step (acc, *addrp, i);
if (*addrp == end)
@@ -146,7 +152,7 @@ __libdw_get_sleb128 (const unsigned char **addrp, const unsigned char *end)
{
/* We only need the low bit of the final byte, and as it is the
sign bit, we don't need to do anything else here. */
- acc |= ((typeof (acc)) b) << 7 * max;
+ acc |= ((__typeof (acc)) b) << 7 * max;
return acc;
}
@@ -179,7 +185,7 @@ __libdw_get_sleb128_unchecked (const unsigned char **addrp)
{
/* We only need the low bit of the final byte, and as it is the
sign bit, we don't need to do anything else here. */
- acc |= ((typeof (acc)) b) << 7 * max;
+ acc |= ((__typeof (acc)) b) << 7 * max;
return acc;
}