Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-8]: src/usr.bin/printf Pull up following revision(s) (requested b...



details:   https://anonhg.NetBSD.org/src/rev/6836e9c76ec2
branches:  netbsd-8
changeset: 435259:6836e9c76ec2
user:      martin <martin%NetBSD.org@localhost>
date:      Sun Sep 23 17:16:33 2018 +0000

description:
Pull up following revision(s) (requested by kre in ticket #1020):
        usr.bin/printf/printf.c: revision 1.46

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

diffstat:

 usr.bin/printf/printf.c |  6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diffs (27 lines):

diff -r b53ce9f02144 -r 6836e9c76ec2 usr.bin/printf/printf.c
--- a/usr.bin/printf/printf.c   Mon Sep 10 17:56:49 2018 +0000
+++ b/usr.bin/printf/printf.c   Sun Sep 23 17:16:33 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: printf.c,v 1.37.8.2 2018/09/01 06:28:23 martin Exp $   */
+/*     $NetBSD: printf.c,v 1.37.8.3 2018/09/23 17:16:33 martin Exp $   */
 
 /*
  * Copyright (c) 1989, 1993
@@ -41,7 +41,7 @@
 #if 0
 static char sccsid[] = "@(#)printf.c   8.2 (Berkeley) 3/22/95";
 #else
-__RCSID("$NetBSD: printf.c,v 1.37.8.2 2018/09/01 06:28:23 martin Exp $");
+__RCSID("$NetBSD: printf.c,v 1.37.8.3 2018/09/23 17:16:33 martin Exp $");
 #endif
 #endif /* not lint */
 
@@ -134,6 +134,8 @@
        (void)setlocale (LC_ALL, "");
 #endif
 
+       rval = 0;       /* clear for builtin versions (avoid holdover) */
+
        while ((o = getopt(argc, argv, "")) != -1) {
                switch (o) {
                case '?':



Home | Main Index | Thread Index | Old Index