diff options
author | Mark Wielaard <mjw@redhat.com> | 2014-04-22 16:43:11 +0200 |
---|---|---|
committer | Mark Wielaard <mjw@redhat.com> | 2014-04-24 11:33:54 +0200 |
commit | eb4da48fa48c69e303b410c4bf7dd7bea8108406 (patch) | |
tree | 00e1e9a0e852bc9c7f754e94b69e3aa8c2cbd275 /libdw | |
parent | fe4b5fd34e25117026f6f96e392009f6f42e3dcc (diff) | |
download | elfutils-eb4da48fa48c69e303b410c4bf7dd7bea8108406.tar.gz |
libdw (get_sleb128_step): Remove undefined behavior.
As pointed out by gcc -fsanitize=undefined left shifting a negative value
is undefined. Replace it with a multiplication of the signed value as
suggested by Richard Henderson and Josh Stone.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Diffstat (limited to 'libdw')
-rw-r--r-- | libdw/ChangeLog | 5 | ||||
-rw-r--r-- | libdw/memory-access.h | 4 |
2 files changed, 7 insertions, 2 deletions
diff --git a/libdw/ChangeLog b/libdw/ChangeLog index 49d70af4..a7b04000 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,3 +1,8 @@ +2014-04-22 Mark Wielaard <mjw@redhat.com> + + * memory-access.h (get_sleb128_step): Remove undefined behavior + of left shifting a signed value. Replace it with a multiplication. + 2014-04-13 Mark Wielaard <mjw@redhat.com> * Makefile.am: Remove !MUDFLAP conditions. diff --git a/libdw/memory-access.h b/libdw/memory-access.h index d0ee63c5..f41f783d 100644 --- a/libdw/memory-access.h +++ b/libdw/memory-access.h @@ -1,5 +1,5 @@ /* Unaligned memory access functionality. - Copyright (C) 2000-2013 Red Hat, Inc. + Copyright (C) 2000-2014 Red Hat, Inc. This file is part of elfutils. Written by Ulrich Drepper <drepper@redhat.com>, 2001. @@ -71,7 +71,7 @@ __libdw_get_uleb128 (const unsigned char **addrp) if (likely ((__b & 0x80) == 0)) \ { \ struct { signed int i:7; } __s = { .i = __b }; \ - (var) |= (typeof (var)) __s.i << ((nth) * 7); \ + (var) |= (typeof (var)) __s.i * ((typeof (var)) 1 << ((nth) * 7)); \ return (var); \ } \ (var) |= (typeof (var)) (__b & 0x7f) << ((nth) * 7); \ |