]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libdw (get_sleb128_step): Remove undefined behavior.
authorMark Wielaard <mjw@redhat.com>
Tue, 22 Apr 2014 14:43:11 +0000 (16:43 +0200)
committerMark Wielaard <mjw@redhat.com>
Thu, 24 Apr 2014 09:33:54 +0000 (11:33 +0200)
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>
libdw/ChangeLog
libdw/memory-access.h

index 49d70af4eee329106fdb6966dba1a10ee5635dd3..a7b0400011517ec606095856d196958e7727d7fb 100644 (file)
@@ -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.
index d0ee63c53f99d170d0064b7232a1256f6451a823..f41f783ddea2aa50993304b346dc5826f386f508 100644 (file)
@@ -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);                     \