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:24:24 +0200
User-agent: KMail/1.9.9

Hi Jim,

> diff --git a/lib/parse-datetime.y b/lib/parse-datetime.y
> index d77955f..23a9a41 100644
> --- a/lib/parse-datetime.y
> +++ b/lib/parse-datetime.y
> @@ -1119,7 +1119,7 @@ yylex (YYSTYPE *lvalp, parser_control *pc)
> 
>            do
>              {
> -              if (p < buff + sizeof buff - 1)
> +              if (p - buff < sizeof buff - 1)
>                  *p++ = c;
>                c = *++pc->input;
>              }
> 

Your patch is correct, but the new code is actually more dangerous
than the previous one: one must be careful when subtracting pointers.
Again, GCC ought to do better. When buff is declared as

         char buff[20];

then a decent compiler MUST know that there is nothing to complain about

         buff + sizeof buff - 1

Have you reported this already?

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



reply via email to

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