<<< Date Index >>>     <<< Thread Index >>>

Re: [PATCH 7 of 9] Fix comparison signedness warning



On 2010-08-06 23:33:29 +0200, Matthias Andree wrote:
> Fix comparison signedness warning.
> 
> diff --git a/pop_lib.c b/pop_lib.c
> --- a/pop_lib.c
> +++ b/pop_lib.c
> @@ -498,7 +498,7 @@
>      strfcpy (inbuf + lenbuf, p, sizeof (buf));
>      pos += chunk;
>  
> -    if (chunk >= sizeof (buf))
> +    if ((size_t)chunk >= sizeof (buf))
>      {
>        lenbuf += strlen (p);
>      }

I would say that a signedness warning would be here a compiler bug
since with a simple variable range analysis, one can deduce that
chunk is non-negative. With such a cast, you may hide a real bug
if the context changes, e.g. because a better compiler would no
longer be able to emit a warning.

FYI, GCC 4.4.5 doesn't have this problem.

xvii:~/software/mutt/mutt> make pop_lib.o
gcc -DPKGDATADIR=\"/home/vinc17/share/mutt\" -DSYSCONFDIR=\"/home/vinc17/etc\" 
-DDOTLOCK_PATH=\"/usr/bin/mutt_dotlock\" 
-DMUTTLOCALEDIR=\"/home/vinc17/share/locale\" -DHAVE_CONFIG_H=1 -I.  -I. -I. 
-I./imap  -Iintl -I./intl  -Wall -pedantic -Wno-long-long -g -O2 -MT pop_lib.o 
-MD -MP -MF .deps/pop_lib.Tpo -c -o pop_lib.o pop_lib.c
mv -f .deps/pop_lib.Tpo .deps/pop_lib.Po

-- 
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / Arénaire project (LIP, ENS-Lyon)