From owner-freebsd-arch Sat Jun 23 6: 9:35 2001 Delivered-To: freebsd-arch@freebsd.org Received: from ringworld.nanolink.com (ringworld.nanolink.com [195.24.48.13]) by hub.freebsd.org (Postfix) with SMTP id 4E01137B407 for ; Sat, 23 Jun 2001 06:09:27 -0700 (PDT) (envelope-from roam@orbitel.bg) Received: (qmail 1823 invoked by uid 1000); 23 Jun 2001 13:07:48 -0000 Date: Sat, 23 Jun 2001 16:07:48 +0300 From: Peter Pentchev To: arch@FreeBSD.org Cc: audit@FreeBSD.org Subject: Re: patch for '%lld' handling in *scanf(3) Message-ID: <20010623160748.C497@ringworld.oblivion.bg> Mail-Followup-To: arch@FreeBSD.org, audit@FreeBSD.org References: <20010623151310.A497@ringworld.oblivion.bg> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20010623151310.A497@ringworld.oblivion.bg>; from roam@orbitel.bg on Sat, Jun 23, 2001 at 03:13:10PM +0300 Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Sat, Jun 23, 2001 at 03:13:10PM +0300, Peter Pentchev wrote: > Hi, > > scanf(3) does not understand %lld for 'long long', it only understands > %qd, and it treats %lld as plain %ld. printf(3) prints out %lld just fine. > The fix needed is just three lines of code, which have been in both NetBSD > and OpenBSD for some time. [snip] > The patch is attached. > > OK, so maybe this patch is not quite semantically correct; it tends > to assume that 'long long' is the same as 'quad', or at least, that > the programmer asked for 'quad' by using %lld. A 'real' fix would > be defining a LONGLONG flag for scanf(). Well, here's a patch that implements %lld the proper way :) G'luck, Peter -- If you think this sentence is confusing, then change one pig. Index: src/lib/libc/stdio/vfscanf.c =================================================================== RCS file: /home/ncvs/src/lib/libc/stdio/vfscanf.c,v retrieving revision 1.16 diff -u -r1.16 vfscanf.c --- src/lib/libc/stdio/vfscanf.c 2001/02/10 05:46:05 1.16 +++ src/lib/libc/stdio/vfscanf.c 2001/06/23 13:09:23 @@ -77,6 +77,7 @@ #define POINTER 0x10 /* weird %p pointer (`fake hex') */ #define NOSKIP 0x20 /* do not skip blanks */ #define QUAD 0x400 +#define LONGLONG 0x800 /* * The following are used in numeric conversions only: @@ -186,7 +187,12 @@ flags |= SUPPRESS; goto again; case 'l': - flags |= LONG; + if (*fmt == 'l') { + fmt++; + flags |= LONGLONG; + } else { + flags |= LONG; + } goto again; case 'q': flags |= QUAD; @@ -290,6 +296,8 @@ *va_arg(ap, short *) = nread; else if (flags & LONG) *va_arg(ap, long *) = nread; + else if (flags & LONGLONG) + *va_arg(ap, long long *) = nread; else if (flags & QUAD) *va_arg(ap, quad_t *) = nread; else @@ -580,6 +588,8 @@ *va_arg(ap, short *) = res; else if (flags & LONG) *va_arg(ap, long *) = res; + else if (flags & LONGLONG) + *va_arg(ap, long long *) = res; else if (flags & QUAD) *va_arg(ap, quad_t *) = res; else To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message