A truly ancient bug found by Edgar Fuss
When printf is running builtin in a sh, global vars aren't reset to 0 between invocations. This affects "rval" which remembers state from a previous %b \c and thereafter always exits after the first format conversion, until we get a conversion that generates an error (which resets the flag almost by accident) printf %b abc\\c abc (no \n) printf %s%s hello world hello (no \n, of course, no world ...) printf %s%s hello world hello printf %s%s hello world hello printf %d hello printf: hello: expected numeric value 0 (no \n) printf %s%s hello world helloworld (no \n, and we are back!) This affects both /bin/sh and /bin/csh (and has for a very long time). XXX pullup -8
This commit is contained in:
parent
5ae421b5b1
commit
f910883c96
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: printf.c,v 1.45 2018/09/04 01:13:50 kre Exp $ */
|
||||
/* $NetBSD: printf.c,v 1.46 2018/09/10 14:42:29 kre Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989, 1993
|
||||
|
@ -41,7 +41,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 1993\
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)printf.c 8.2 (Berkeley) 3/22/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: printf.c,v 1.45 2018/09/04 01:13:50 kre Exp $");
|
||||
__RCSID("$NetBSD: printf.c,v 1.46 2018/09/10 14:42:29 kre Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
|
@ -136,6 +136,8 @@ main(int argc, char *argv[])
|
|||
(void)setlocale (LC_ALL, "");
|
||||
#endif
|
||||
|
||||
rval = 0; /* clear for builtin versions (avoid holdover) */
|
||||
|
||||
while ((o = getopt(argc, argv, "")) != -1) {
|
||||
switch (o) {
|
||||
case '?':
|
||||
|
|
Loading…
Reference in New Issue