-Wsign-compare warning in lempar.c

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

-Wsign-compare warning in lempar.c

nwellnhof
With the latest Lemon code, I get a warning under GCC with -Wsign-compare:

warning: comparison between signed and unsigned integer expressions
[-Wsign-compare]
      assert( i>=0 && i+YYNTOKEN<=sizeof(yy_lookahead)/sizeof(yy_lookahead[0]) );
                                ^

Nick
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: -Wsign-compare warning in lempar.c

Richard Damon
On 2/8/18 9:21 AM, Nick Wellnhofer wrote:

> With the latest Lemon code, I get a warning under GCC with
> -Wsign-compare:
>
> warning: comparison between signed and unsigned integer expressions
> [-Wsign-compare]
>      assert( i>=0 &&
> i+YYNTOKEN<=sizeof(yy_lookahead)/sizeof(yy_lookahead[0]) );
>                                ^
>
> Nick
Looks like not a problem. The danger of comparing a signed value to an
unsigned is that you can get an unexpected result if the signed value is
negative, but in this case we first check that i is positive, so that
issue never occurs.

--
Richard Damon

_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: -Wsign-compare warning in lempar.c

Richard Hipp-3
On 2/9/18, Richard Damon <[hidden email]> wrote:

> On 2/8/18 9:21 AM, Nick Wellnhofer wrote:
>> With the latest Lemon code, I get a warning under GCC with
>> -Wsign-compare:
>>
>> warning: comparison between signed and unsigned integer expressions
>> [-Wsign-compare]
>>      assert( i>=0 &&
>> i+YYNTOKEN<=sizeof(yy_lookahead)/sizeof(yy_lookahead[0]) );
>>                                ^
>>
>> Nick
> Looks like not a problem. The danger of comparing a signed value to an
> unsigned is that you can get an unexpected result if the signed value is
> negative, but in this case we first check that i is positive, so that
> issue never occurs.

Correct.  The previous term of the assert() guarantees that variable i
is non-negative.

This is nuisance warning (as are most warnings, actually).  We'll fix
it though, just to reduce bandwidth on the mailing list.

--
D. Richard Hipp
[hidden email]
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users