diff mbox

[v2] Fix signed integer overflow in gcc/data-streamer.c

Message ID 20140928125710.GB302@x4
State New
Headers show

Commit Message

Markus Trippelsdorf Sept. 28, 2014, 12:57 p.m. UTC
On 2014.09.28 at 14:36 +0200, Steven Bosscher wrote:
> 
> Can you use HOST_WIDE_INT_1U for this?

Sure. Thanks for the suggestion. 
(Fix now resembles similar idiom in data-streamer-in.c)

2014-09-28  Markus Trippelsdorf  <markus@trippelsdorf.de>

	* data-streamer.c (bp_unpack_var_len_int): Avoid signed
	integer overflow.

Comments

Markus Trippelsdorf Sept. 30, 2014, 7:09 a.m. UTC | #1
On 2014.09.28 at 14:57 +0200, Markus Trippelsdorf wrote:
> On 2014.09.28 at 14:36 +0200, Steven Bosscher wrote:
> > 
> > Can you use HOST_WIDE_INT_1U for this?
> 
> Sure. Thanks for the suggestion. 
> (Fix now resembles similar idiom in data-streamer-in.c)

I checked in the fix as obvious.
Diego Novillo Sept. 30, 2014, 3:37 p.m. UTC | #2
On Tue, Sep 30, 2014 at 3:09 AM, Markus Trippelsdorf
<markus@trippelsdorf.de> wrote:
> On 2014.09.28 at 14:57 +0200, Markus Trippelsdorf wrote:
>> On 2014.09.28 at 14:36 +0200, Steven Bosscher wrote:
>> >
>> > Can you use HOST_WIDE_INT_1U for this?
>>
>> Sure. Thanks for the suggestion.
>> (Fix now resembles similar idiom in data-streamer-in.c)
>
> I checked in the fix as obvious.

Sorry for the delay. Yes, the fix is obvious. Thanks.
diff mbox

Patch

diff --git a/gcc/data-streamer.c b/gcc/data-streamer.c
index 0e19c72162aa..785beb5165fa 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 |= - (HOST_WIDE_INT_1U << shift);
 
 	  return result;
 	}