This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix signed integer overflow in gcc/data-streamer.c
- From: Markus Trippelsdorf <markus at trippelsdorf dot de>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Diego Novillo <dnovillo at google dot com>
- Date: Sun, 28 Sep 2014 14:22:18 +0200
- Subject: [PATCH] Fix signed integer overflow in gcc/data-streamer.c
- Authentication-results: sourceware.org; auth=none
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.
Boostrapped and tested on x86_64-unknown-linux-gnu.
OK for trunk?
Thanks.
2014-09-28 Markus Trippelsdorf <markus@trippelsdorf.de>
* data-streamer.c (bp_unpack_var_len_int): Avoid signed
integer overflow.
diff --git a/gcc/data-streamer.c b/gcc/data-streamer.c
index 0e19c72162aa..0760ed590c22 100644
--- a/gcc/data-streamer.c
+++ b/gcc/data-streamer.c
@@ -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 |= - ((unsigned HOST_WIDE_INT)1 << shift);
return result;
}
--
Markus