Module Name:    src
Committed By:   kre
Date:           Fri Aug 31 17:27:35 UTC 2018

Modified Files:
        src/usr.bin/printf: printf.1 printf.c

Log Message:
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


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/usr.bin/printf/printf.1
cvs rdiff -u -r1.42 -r1.43 src/usr.bin/printf/printf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/printf/printf.1
diff -u src/usr.bin/printf/printf.1:1.30 src/usr.bin/printf/printf.1:1.31
--- src/usr.bin/printf/printf.1:1.30	Tue Jul 24 20:58:39 2018
+++ src/usr.bin/printf/printf.1	Fri Aug 31 17:27:35 2018
@@ -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 @@ The format characters and their meanings
 .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

Index: src/usr.bin/printf/printf.c
diff -u src/usr.bin/printf/printf.c:1.42 src/usr.bin/printf/printf.c:1.43
--- src/usr.bin/printf/printf.c:1.42	Wed Jul 25 15:35:27 2018
+++ src/usr.bin/printf/printf.c	Fri Aug 31 17:27:35 2018
@@ -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 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 19
 #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 char	 getchr(void);
 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 @@ int main(int argc, char *argv[])
 			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 @@ getintmax(void)
 	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)
 {

Reply via email to