diff options
| author | kre <kre@NetBSD.org> | 2018-08-31 17:27:35 +0000 |
|---|---|---|
| committer | kre <kre@NetBSD.org> | 2018-08-31 17:27:35 +0000 |
| commit | 48d6da036cf3d7623f98d2d600ff68406285550f (patch) | |
| tree | ef6945a79ab87c44eb53555251a00abe41cde27a /usr.bin/printf/printf.c | |
| parent | a7da9958179b15c603602d12dcd4427bcf8a3b9f (diff) | |
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 (limited to 'usr.bin/printf/printf.c')
| -rw-r--r-- | usr.bin/printf/printf.c | 36 |
1 files changed, 3 insertions, 33 deletions
diff --git a/usr.bin/printf/printf.c b/usr.bin/printf/printf.c index 28fb740c212..aa4738904b9 100644 --- a/usr.bin/printf/printf.c +++ b/usr.bin/printf/printf.c @@ -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, 1993\ #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) { |
