Date: Thu, 30 Dec 2004 13:40:22 GMT From: Bruce Evans <bde@zeta.org.au> To: freebsd-bugs@FreeBSD.org Subject: Re: bin/75638: sscanf %lld broken on 4.x Message-ID: <200412301340.iBUDeMcK061320@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/75638; it has been noted by GNATS. From: Bruce Evans <bde@zeta.org.au> To: Przemyslaw Frasunek <venglin@freebsd.lublin.pl> Cc: freebsd-gnats-submit@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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200412301340.iBUDeMcK061320>