Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/printf PR standards/53563



details:   https://anonhg.NetBSD.org/src/rev/f36789fda1e8
branches:  trunk
changeset: 366521:f36789fda1e8
user:      kre <kre%NetBSD.org@localhost>
date:      Fri Aug 31 17:27:35 2018 +0000

description:
PR standards/53563

POSIX requires that signed numbers (strings preceded by '+' or '-')
be allowed as inputs to all of the integer format conversions, including
those which treat the data as unsigned.

Hence we do not need a variant function whose only difference from its
companion is to reject strings starting with '-' - instead we use
the primary function (getintmax()) for everything and remove getuintmax().

Minor update to the man page to indicate that the arg to all of the
integer conversions (diouxX) must be an integer constant (with an
optional sign) and to make it blatantly clear that %o is octal and
%u is unsigned decimal (for some reason those weren't explicitly stated
unlike d i x and X).  Delete "respectively", it is not needed (and does
not really apply).

XXX pullup -8

diffstat:

 usr.bin/printf/printf.1 |  13 ++++++++-----
 usr.bin/printf/printf.c |  36 +++---------------------------------
 2 files changed, 11 insertions(+), 38 deletions(-)

diffs (105 lines):

diff -r 2aa2f85412be -r f36789fda1e8 usr.bin/printf/printf.1
--- a/usr.bin/printf/printf.1   Fri Aug 31 16:43:26 2018 +0000
+++ b/usr.bin/printf/printf.1   Fri Aug 31 17:27:35 2018 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: printf.1,v 1.30 2018/07/24 20:58:39 kre Exp $
+.\"    $NetBSD: printf.1,v 1.31 2018/08/31 17:27:35 kre Exp $
 .\"
 .\" Copyright (c) 1989, 1990, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -32,7 +32,7 @@
 .\"
 .\"    from: @(#)printf.1      8.1 (Berkeley) 6/6/93
 .\"
-.Dd July 25, 2018
+.Dd August 31, 2018
 .Dt PRINTF 1
 .Os
 .Sh NAME
@@ -255,9 +255,12 @@
 .Bl -tag -width Fl
 .It Cm diouXx
 The
-.Ar argument
-is printed as a signed decimal (d or i), unsigned octal, unsigned decimal,
-or unsigned hexadecimal (X or x), respectively.
+.Ar argument ,
+which must represent an integer constant,
+with an optional leading plus or minus sign,
+is printed as a signed decimal (d or i),
+unsigned octal (o), unsigned decimal (u),
+or unsigned hexadecimal (X or x).
 .It Cm fF
 The
 .Ar argument
diff -r 2aa2f85412be -r f36789fda1e8 usr.bin/printf/printf.c
--- a/usr.bin/printf/printf.c   Fri Aug 31 16:43:26 2018 +0000
+++ b/usr.bin/printf/printf.c   Fri Aug 31 17:27:35 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: printf.c,v 1.42 2018/07/25 15:35:27 kre Exp $  */
+/*     $NetBSD: printf.c,v 1.43 2018/08/31 17:27:35 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.42 2018/07/25 15:35:27 kre Exp $");
+__RCSID("$NetBSD: printf.c,v 1.43 2018/08/31 17:27:35 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -72,7 +72,6 @@
 static double   getdouble(void);
 static int      getwidth(void);
 static intmax_t         getintmax(void);
-static uintmax_t getuintmax(void);
 static char    *getstr(void);
 static char    *mklong(const char *, char);
 static void      check_conversion(const char *, const char *);
@@ -301,7 +300,7 @@
                        case 'u':
                        case 'x':
                        case 'X': {
-                               uintmax_t p = getuintmax();
+                               uintmax_t p = (uintmax_t)getintmax();
                                char *f = mklong(start, ch);
 
                                PF(f, p);
@@ -655,35 +654,6 @@
        return val;
 }
 
-static uintmax_t
-getuintmax(void)
-{
-       uintmax_t val;
-       char *cp, *ep;
-
-       cp = *gargv;
-       if (cp == NULL)
-               return 0;
-       gargv++;
-
-       if (*cp == '\"' || *cp == '\'')
-               return (uintmax_t)*(cp + 1);
-
-       /* strtoumax won't error -ve values */
-       while (isspace(*(unsigned char *)cp))
-               cp++;
-       if (*cp == '-') {
-               warnx("%s: expected positive numeric value", cp);
-               rval = 1;
-               return 0;
-       }
-
-       errno = 0;
-       val = strtoumax(cp, &ep, 0);
-       check_conversion(cp, ep);
-       return val;
-}
-
 static double
 getdouble(void)
 {



Home | Main Index | Thread Index | Old Index