Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/printf Stop assuming that printf handles options in ...



details:   https://anonhg.NetBSD.org/src/rev/e1bd234e2ab0
branches:  trunk
changeset: 461971:e1bd234e2ab0
user:      kre <kre%NetBSD.org@localhost>
date:      Sun Jul 21 15:25:39 2019 +0000

description:
Stop assuming that printf handles options in any way at all
(it doesn't - that is, shouldn't) which includes processing -- as an
"end of options".  The first arg is (always) the format string.

Remove call to getopt() (but still do associated changes to argc/argv)

Note: for now this is #if 0's out instead of being deleted, the old
code should be fully removed sometime soon.

Problem pointed out on tech-userlevel by Thierry Laronde.

diffstat:

 usr.bin/printf/printf.c |  17 ++++++++++++++---
 1 files changed, 14 insertions(+), 3 deletions(-)

diffs (52 lines):

diff -r e6a5e2496096 -r e1bd234e2ab0 usr.bin/printf/printf.c
--- a/usr.bin/printf/printf.c   Sun Jul 21 15:00:18 2019 +0000
+++ b/usr.bin/printf/printf.c   Sun Jul 21 15:25:39 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: printf.c,v 1.48 2019/01/27 12:03:09 kre Exp $  */
+/*     $NetBSD: printf.c,v 1.49 2019/07/21 15:25:39 kre 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.48 2019/01/27 12:03:09 kre Exp $");
+__RCSID("$NetBSD: printf.c,v 1.49 2019/07/21 15:25:39 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -130,7 +130,7 @@
        char nextch;
        char *format;
        char ch;
-       int error, o;
+       int error;
 
 #if !defined(SHELL) && !defined(BUILTIN)
        (void)setlocale (LC_ALL, "");
@@ -138,6 +138,13 @@
 
        rval = 0;       /* clear for builtin versions (avoid holdover) */
 
+#if 0
+       int o;
+
+       /*
+        * printf does not comply with Posix XBD 12.2 - there are no opts,
+        * not even the -- end of options marker.   Do not run getoot().
+        */
        while ((o = getopt(argc, argv, "")) != -1) {
                switch (o) {
                case '?':
@@ -148,6 +155,10 @@
        }
        argc -= optind;
        argv += optind;
+#else
+       argc -= 1;
+       argv += 1;
+#endif
 
        if (argc < 1) {
                usage();



Home | Main Index | Thread Index | Old Index