Fix signed integer overflow in data-streamer.c
authorMarkus Trippelsdorf <markus@trippelsdorf.de>
Tue, 30 Sep 2014 07:07:55 +0000 (07:07 +0000)
committerMarkus Trippelsdorf <trippels@gcc.gnu.org>
Tue, 30 Sep 2014 07:07:55 +0000 (07:07 +0000)
Running the testsuite with a -fsanitize=undefined instrumented compiler
shows:
 % gcc -O2 -flto -fno-use-linker-plugin -flto-partition=none testsuite/gcc.dg/torture/pr28045.c
gcc/data-streamer.c:113:45: runtime error: negation of -9223372036854775808 cannot be represented in type 'long int'; cast to an unsigned type to negate this value to itself

The fix is obvious.

From-SVN: r215706

gcc/ChangeLog
gcc/data-streamer.c

index 1714cec184490af1a45f266236dd1d409a064400..c5a4a86d5c6c91a63c7fff088848254e9053d68e 100644 (file)
@@ -1,3 +1,8 @@
+2014-09-30  Markus Trippelsdorf  <markus@trippelsdorf.de>
+
+       * data-streamer.c (bp_unpack_var_len_int): Avoid signed
+       integer overflow.
+
 2014-09-29  Andi Kleen  <ak@linux.intel.com>
 
        * opts.c (print_filtered_help): Print --param min/max/default
index 0e19c72162aa829c94fb94b82bff22a90b456d98..785beb5165fa720cdafc7d7a6c26c41338ffb346 100644 (file)
@@ -110,7 +110,7 @@ bp_unpack_var_len_int (struct bitpack_d *bp)
       if ((half_byte & 0x8) == 0)
        {
          if ((shift < HOST_BITS_PER_WIDE_INT) && (half_byte & 0x4))
-           result |= - ((HOST_WIDE_INT)1 << shift);
+           result |= - (HOST_WIDE_INT_1U << shift);
 
          return result;
        }