On Tue, Sep 29, 2009 at 06:38:44AM -0400, D. Richard Hipp wrote:
> 
> On Sep 27, 2009, at 5:28 PM, Dr. David Kirkby wrote:
> 
> > "sqlite3.c", line 18731: warning: integer overflow detected: op "<<"
> > "sqlite3.c", line 18748: warning: integer overflow detected: op "<<"
> 
> Both cases are complaining about a constant:  (0x1f<<28)    Both are  
> harmless.

They are constants, but 0x1f<<28 is being assigned to an unsigned,
32-bit integer variable, so the constant expression does overflow.  The
compiler is right to warn about that, even you've taken the overflow
into account.

I take no position on whether these warnings should be fixed.  If you
don't fix them though, a comment in the source (and an FAQ) would be
nice, as it will head off future questions about this.

If you do fix it, the fix could be to change the 1f to f, or to put an
explicit cast to the type of the variable.  Both are arguably dangerous
fixes: what if you later change the type of those variables to be u64?
I don't think that's likely in this case (varint encoding isn't going to
change, is it?), but it's something to consider.  If you're willing to
use GNU C extensions then you could use typeof() (which Sun Studio 12
does support) in the cast expression, in which case there'd be no
danger.

> > "sqlite3.c", line 32546: warning: statement not reached
> 
> Complains about this code:
> 
>      /*NOTREACHED*/
>      assert( 0 );
> 
> Harmless.

Indeed.  I'm not sure why the compiler warned about this one (the
NOTREACHED comment is for lint, but the compiler ought honor it).  I'll
ask here how to make that warning go away.

> > "sqlite3.c", line 69160: warning: integer overflow detected: op "<<"
> 
> Complains about this constant:   (((sqlite3_int64)1)<<63)   Harmless

That too is a legitimate warning, even if you've taken the overflow into
account (the compiler can't know that you did).  If you move the cast to
the left the warning should go away: ((sqlite3_int64)(1L<<63)), or you
could use a constant for the most negative value that sqlite3_int64 can
hold ((- 2^63) - 1).

Nico
-- 
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to