sqldiff.c : 2 benign warnings in 64 bits builds

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

sqldiff.c : 2 benign warnings in 64 bits builds

Olivier Mascia
Hello,

May I suggest to patch sqldiff.c (3.10.0) on lines 997 and 1144 as this:

    return (int)(zDelta - zOrigDelta);

instead of:

    return zDelta - zOrigDelta;

to suppress the benign warning about __int64 being converted to int which some compilers can emit because the difference of two pointers is a 64 bits value.

--
Meilleures salutations, Met vriendelijke groeten, Best Regards,
Olivier Mascia, integral.be/om


_______________________________________________
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: sqldiff.c : 2 benign warnings in 64 bits builds

Olivier Mascia
Hello,

Using (3.10.2), as was the case with 3.10.0, there are two warnings (VS.2015 at least, /W3 only) compiling in 64 bits:

sqldiff.c(997): warning C4244: 'return': conversion from '__int64' to 'int', possible loss of data
sqldiff.c(1144): warning C4244: 'return': conversion from '__int64' to 'int', possible loss of data

In both locations, changing:

    return zDelta - zOrigDelta;

to:

    return (int)(zDelta - zOrigDelta);

fixes it as the difference of two pointers is a 64 bits value while the function returns int.
There is nothing wrong at leaving it as is, it just would look better with the cast.

--
Meilleures salutations, Met vriendelijke groeten, Best Regards,
Olivier Mascia, integral.be/om

> Le 14 janv. 2016 à 10:55, Olivier Mascia <[hidden email]> a écrit :
>
> Hello,
>
> May I suggest to patch sqldiff.c (3.10.0) on lines 997 and 1144 as this:
>
>    return (int)(zDelta - zOrigDelta);
>
> instead of:
>
>    return zDelta - zOrigDelta;
>
> to suppress the benign warning about __int64 being converted to int which some compilers can emit because the difference of two pointers is a 64 bits value.
>
> --
> Meilleures salutations, Met vriendelijke groeten, Best Regards,
> Olivier Mascia, integral.be/om
>
>
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

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

signature.asc (859 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: sqldiff.c : 2 benign warnings in 64 bits builds

Richard Hipp-3
On 1/26/16, Olivier Mascia <[hidden email]> wrote:
> Hello,
>
> Using (3.10.2), as was the case with 3.10.0, there are two warnings (VS.2015
> at least, /W3 only) compiling in 64 bits:
>

Fixed 12 days ago on trunk.  https://www.sqlite.org/src/info/74808a79ea3194f6

--
D. Richard Hipp
[hidden email]
_______________________________________________
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: sqldiff.c : 2 benign warnings in 64 bits builds

J Decker
should be (size_t) instead of (int) though... since size_t will retain
the precision... and then back propagate the change to the function
return type and the things receiving the return... then you don't need
the cast anyway.

On Tue, Jan 26, 2016 at 3:37 AM, Richard Hipp <[hidden email]> wrote:

> On 1/26/16, Olivier Mascia <[hidden email]> wrote:
>> Hello,
>>
>> Using (3.10.2), as was the case with 3.10.0, there are two warnings (VS.2015
>> at least, /W3 only) compiling in 64 bits:
>>
>
> Fixed 12 days ago on trunk.  https://www.sqlite.org/src/info/74808a79ea3194f6
>
> --
> D. Richard Hipp
> [hidden email]
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
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: sqldiff.c : 2 benign warnings in 64 bits builds

Stephan Beal-3
On Tue, Jan 26, 2016 at 3:47 PM, J Decker <[hidden email]> wrote:

> should be (size_t) instead of (int) though... since size_t will retain
> the precision... and then back propagate the change to the function
> return type and the things receiving the return... then you don't need
> the cast anyway.
>

fwiw, in case this matters: size_t has an unspecified size and it's not in
C89. It's defined by C99 in stddef.h

--
----- stephan beal
http://wanderinghorse.net/home/stephan/
http://gplus.to/sgbeal
"Freedom is sloppy. But since tyranny's the only guaranteed byproduct of
those who insist on a perfect world, freedom will have to do." -- Bigby Wolf
_______________________________________________
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: sqldiff.c : 2 benign warnings in 64 bits builds

Scott Robison-2
On Tue, Jan 26, 2016 at 8:21 AM, Stephan Beal <[hidden email]> wrote:

> On Tue, Jan 26, 2016 at 3:47 PM, J Decker <[hidden email]> wrote:
>
> > should be (size_t) instead of (int) though... since size_t will retain
> > the precision... and then back propagate the change to the function
> > return type and the things receiving the return... then you don't need
> > the cast anyway.
> >
>
> fwiw, in case this matters: size_t has an unspecified size and it's not in
> C89. It's defined by C99 in stddef.h
>

size_t (and ptrdiff_t) are both in C89/C90 in stddef.h. Really ptrdiff_t is
what one wants for the difference between two pointers. Their size is
platform specified.

As far as casting goes, I dislike casting unless absolutely necessary. I
will do it to shut up compiler warnings if there is nothing better and I
can guarantee that the difference can never exceed the size of the
destination type, and perhaps that guarantee is possible here. Too often
(not in SQLite necessarily but in other projects) I see people casting
without consideration to the size requirements just because of the warning.

Given that most of my code is C++, I really like the numeric_cast. It
inlines to a normal cast in cases where there is no danger (non-truncating
conversions) and can throw an exception in the case of a truncating or
signed conversion that is out of range. Sadly, something like that isn't
possible in pure C89.

--
Scott Robison
_______________________________________________
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: sqldiff.c : 2 benign warnings in 64 bits builds

Stephan Beal-3
On Tue, Jan 26, 2016 at 6:40 PM, Scott Robison <[hidden email]>
wrote:

> On Tue, Jan 26, 2016 at 8:21 AM, Stephan Beal <[hidden email]>
> wrote:
> > fwiw, in case this matters: size_t has an unspecified size and it's not
> in
> > C89. It's defined by C99 in stddef.h
> >
>
> size_t (and ptrdiff_t) are both in C89/C90 in stddef.h. Really ptrdiff_t is
> what one wants for the difference between two pointers. Their size is
> platform specified.
>

Indeed, my apologies for the misinformation - i had misinterpreted my
source as being exclusive to c99.

--
----- stephan beal
http://wanderinghorse.net/home/stephan/
http://gplus.to/sgbeal
"Freedom is sloppy. But since tyranny's the only guaranteed byproduct of
those who insist on a perfect world, freedom will have to do." -- Bigby Wolf
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users