bin/75638: sscanf %lld broken on 4.x

Bruce Evans bde at zeta.org.au
Thu Dec 30 05:40:23 PST 2004


The following reply was made to PR bin/75638; it has been noted by GNATS.

From: Bruce Evans <bde at zeta.org.au>
To: Przemyslaw Frasunek <venglin at freebsd.lublin.pl>
Cc: freebsd-gnats-submit at FreeBSD.org
Subject: Re: bin/75638: sscanf %lld broken on 4.x
Date: Fri, 31 Dec 2004 00:32:40 +1100 (EST)

 On Wed, 29 Dec 2004, Przemyslaw Frasunek wrote:
 
 >   > sscanf(s, "%lld", &l) will not set l to valid value if l was previously
 >   > not zero.
 >
 >  well, not exactly non-zero. the problem occurs when l if initialized with value
 >  greater than 0xffffffff:
 
 The bug is actually that %lld is not supported in RELENG_4 (or C90).  Ports
 and other code that use it are broken (unportable).  %q must be used in
 RELENG_4.  From `man scanf':
 
 %      q       Indicates either that the conversion will be one of dioux or n
 %              and the next pointer is a pointer to a long long int (rather than
 %              int),
 
 This is the only support claimed for long long in scanf in RELENG_4.
 Note that "q" format is unsuitable for printing quad_t's, unlike what
 its name suggests, since quad_t may be different from long long, and
 is different on all supported 64-bit arches.  Thus the requirements
 for printing quads and long longs in RELENG_4 are weird: quads can be
 printed with %q formats but must be passed as long longs, while long
 longs can't be printed with %lld format but can be passed as long longs.
 
 Unfortunately, gcc's format checker also doesn't understand the difference
 between "q" and "ll" conversions, and doesn't know that old versions of
 scanf (and older versions of printf) don't support "ll", so gcc -Wformat
 cannot help avoid using undefined %ll conversion specifiers.  It can
 sometimes detect the relatively benign type mismatch between quads and
 %q.
 
 Bruce


More information about the freebsd-bugs mailing list