Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 23 Jun 2001 16:07:48 +0300
From:      Peter Pentchev <roam@orbitel.bg>
To:        arch@FreeBSD.org
Cc:        audit@FreeBSD.org
Subject:   Re: patch for '%lld' handling in *scanf(3)
Message-ID:  <20010623160748.C497@ringworld.oblivion.bg>
In-Reply-To: <20010623151310.A497@ringworld.oblivion.bg>; from roam@orbitel.bg on Sat, Jun 23, 2001 at 03:13:10PM %2B0300
References:  <20010623151310.A497@ringworld.oblivion.bg>

next in thread | previous in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010623160748.C497>