brl: don't use conversion to float for offset and count
Andrew Bartlett
abartlet at samba.org
Wed Jun 4 02:33:09 MDT 2014
On Tue, 2014-06-03 at 15:41 +0200, Volker Lendecke wrote:
> On Sun, Jun 01, 2014 at 08:37:18PM +0200, Ralph Böhme wrote:
> > Hi
> >
> > attached is a small fix, that deals with wrong results by printf()
> > conversion from integer to float when printing lock offsets and
> > sizes. For large values such a conversion may produce wrong results,
> > instead use one of the standard conversion specifiers for integers.
> >
> > Example: The integer
> >
> > 9223372036854775798 (= 0x7FFFFFFFFFFFFFF6)
> >
> > is printed as
> >
> > 9223372036854775808 (= 0x7FFFFFFFFFFFFFFF)
> >
> > when using a cast to float (double) and a double conversion specifier.
> >
> > Review appreciated.
>
> Thanks, good catch!
>
> https://en.wikipedia.org/wiki/Inttypes.h
>
> has PRIu64 as the format specifier for a uint64_t. If you
> look deep inside
>
> http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf
>
> it seems that this is C99 standard these days. Samba does
> already use this in various places.
>
> I could not find a reference to "j" in C99, only in susv4.
> Both are probably possible, but for orthogonality reasons I
> would argue to settle on one of both.
I don't like "j" because I've never seen it before, and we shouldn't
start using stuff that isn't in C99. In other places, we have used %llu
to get 'close enough' to 64-bit, but given this has already bitten us
once, and these values only make sense as exactly 64 bit I think
starting to use the PRIu64 notation, while ugly, is the best option.
Andrew Bartlett
--
Andrew Bartlett http://samba.org/~abartlet/
Authentication Developer, Samba Team http://samba.org
Samba Developer, Catalyst IT http://catalyst.net.nz/services/samba
More information about the samba-technical
mailing list