From owner-freebsd-bugs@FreeBSD.ORG Thu Dec 30 13:40:23 2004 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0F03A16A4CE for ; Thu, 30 Dec 2004 13:40:23 +0000 (GMT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id EBA7743D41 for ; Thu, 30 Dec 2004 13:40:22 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.1/8.13.1) with ESMTP id iBUDeM9A061321 for ; Thu, 30 Dec 2004 13:40:22 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.1/8.13.1/Submit) id iBUDeMcK061320; Thu, 30 Dec 2004 13:40:22 GMT (envelope-from gnats) Date: Thu, 30 Dec 2004 13:40:22 GMT Message-Id: <200412301340.iBUDeMcK061320@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Bruce Evans Subject: Re: bin/75638: sscanf %lld broken on 4.x X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Bruce Evans List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Dec 2004 13:40:23 -0000 The following reply was made to PR bin/75638; it has been noted by GNATS. From: Bruce Evans To: Przemyslaw Frasunek 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