From owner-freebsd-audit Wed Jun 27 5:57:29 2001 Delivered-To: freebsd-audit@freebsd.org Received: from mailman.zeta.org.au (mailman.zeta.org.au [203.26.10.16]) by hub.freebsd.org (Postfix) with ESMTP id 1148B37B405; Wed, 27 Jun 2001 05:57:23 -0700 (PDT) (envelope-from bde@zeta.org.au) Received: from bde.zeta.org.au (bde.zeta.org.au [203.2.228.102]) by mailman.zeta.org.au (8.9.3/8.8.7) with ESMTP id WAA06846; Wed, 27 Jun 2001 22:57:15 +1000 Date: Wed, 27 Jun 2001 22:55:20 +1000 (EST) From: Bruce Evans X-Sender: bde@besplex.bde.org To: Peter Pentchev Cc: arch@FreeBSD.ORG, audit@FreeBSD.ORG, freebsd-standards@bostonradio.org Subject: Re: patch for '%lld' handling in *scanf(3) In-Reply-To: <20010627140322.C19162@ringworld.oblivion.bg> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Wed, 27 Jun 2001, Peter Pentchev wrote: > Somebody told me in private mail that this change should be accompanied > by an update to the scanf(3) manual page. At a quick look at the manual > page, the 'q' modifier is documented as providing a 'long long int' value. This is a bug IMO. 'q' provides a quad_t value (but see below). > Thus, it seems that 'q' and 'll' should be equivalent, if 'q' is documented > as doing exactly what 'll' should do. 'll' provides a 'long long' value, although it is currently (mis)implemented by type punning long iongs to quad_t's. > What to do now? Use my first patch (with 'll' adding QUAD to the flag), > or define the new LONGLONG type? If the latter, should 'q' retain the QUAD > type, or use the LONGLONG type? In any case, how should the manpage > be worded (WRT both 'll' and 'q')? Use your second patch. Also, implement it right by not type punning long longs as quads or using strtoq() to parse them (use strtoll()). Maybe fix the longstanding breakage of overflow handling from misusing strtoq() instead of strtol() to parse long values while you are there. > FWIW, here's a chart of the current situation in the several BSD's: > > LONGLONG flag QUAD flag %lld type %qd type > > FreeBSD no no none quad_t > OpenBSD no yes quad quad_t > NetBSD yes yes long long quad_t This oversimplifes things :-). %qd is for quad_t's, but gcc's format checker thinks that it is for long longs (at least for printf, and I think scanf is no different here. Since quad_t's are plain longs on some machines (alphas), %qd is unusable in practice (in code that must compile with WARNS=2, etc.). > All the manpages document 'q' as producing a 'long long', and none > of the manpages mention 'll'. The FreeBSD printf.3 documents this correctly. quad_t and %q should go away when C99's intmax_t and %j become Normal. I think it is time to deprecate them in man pages. (%q is already deprecated in the kernel by not permitting it in FreeBSD's version of gcc's format checker for gcc -fformat-extensions.) long long and %ll unfortunately won't go away, but using them will usually be wrong. Bruce To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message