bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: two small patches to accommodate -Wstrict-overflow


From: Bruno Haible
Subject: Re: two small patches to accommodate -Wstrict-overflow
Date: Sun, 29 May 2011 21:20:11 +0200
User-agent: KMail/1.9.9

Hi Jim,

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.

Bruno
-- 
In memoriam John Penry <http://en.wikipedia.org/wiki/John_Penry>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]