Date: Sat, 23 Jun 2001 15:13:10 +0300 From: Peter Pentchev <roam@orbitel.bg> To: arch@FreeBSD.org Cc: audit@FreeBSD.org Subject: patch for '%lld' handling in *scanf(3) Message-ID: <20010623151310.A497@ringworld.oblivion.bg>
next in thread | raw e-mail | index | archive | help
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. Demonstration: the following program: #include <sys/types.h> #include <stdio.h> int main(void) { quad_t x = 0xeFFFFFFFFFFFFFFe; scanf("%lld", &x); printf("%llx\n", x); return (0); } Before: [roam@freefall ~/c/misc/foo]$ ./foo7 5 efffffff00000005 [roam@freefall ~/c/misc/foo]$ After: [roam@ringworld:v4 ~/c/misc/foo]$ ./foo7 5 5 [roam@ringworld:v4 ~/c/misc/foo]$ 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(). G'luck, Peter -- When you are not looking at it, this sentence is in Spanish. 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 12:12:30 @@ -186,7 +186,12 @@ flags |= SUPPRESS; goto again; case 'l': - flags |= LONG; + if (*fmt == 'l') { + fmt++; + flags |= QUAD; + } else { + flags |= LONG; + } goto again; case 'q': flags |= QUAD; To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010623151310.A497>