[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: two small patches to accommodate -Wstrict-overflow
From: |
Jim Meyering |
Subject: |
Re: two small patches to accommodate -Wstrict-overflow |
Date: |
Mon, 30 May 2011 19:01:08 +0200 |
Bruno Haible wrote:
> Jim Meyering wrote:
>> diff --git a/lib/trim.c b/lib/trim.c
>> index 1f4d0c1..6515cfa 100644
>> --- a/lib/trim.c
>> +++ b/lib/trim.c
>> @@ -65,7 +65,7 @@ trim2 (const char *s, int how)
>> /* Trim trailing whitespaces. */
>> if (how != TRIM_LEADING)
>> {
>> - int state = 0;
>> + unsigned int state = 0;
>> char *r IF_LINT (= NULL); /* used only while state = 2 */
>>
>> mbi_init (i, d, strlen (d));
>
> I don't care whether this variable is 'int' or 'unsigned int', but have you
> reported a GCC bug for this one? The variable 'state' is assigned only the
> values 0, 1, 2, always a constant right-hand side, and the only operation that
> is performed on it is ==. There is *nothing* dangerous about it.
>
> $ /arch/x86-linux/gnu-inst-gcc/4.6.0/bin/gcc -I . -I../.. -O2 -S
> trim.c -Wstrict-overflow
> trim.c: In function 'trim2':
> trim.c:81:18: warning: assuming signed overflow does not occur when
> simplifying conditional to constant [-Wstrict-overflow]
>
> The code in line 81 is as safe as the code in line 75 - for which no warning
> was issued.
>
> And whether the type is 'int' or 'unsigned int' should not matter at all
> because all possible values are 0, 1, 2.
I've reported this one with a minimal test case:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49234