klibc-bot for Herbert Xu
2020-Mar-28 21:48 UTC
[klibc] [klibc:update-dash] dash: [BUILTIN] Remove getintmax in printf
Commit-ID: bdfdde71b9ec8f4678f498445d38f5361bb08138 Gitweb: http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=bdfdde71b9ec8f4678f498445d38f5361bb08138 Author: Herbert Xu <herbert at gondor.apana.org.au> AuthorDate: Mon, 27 Oct 2014 16:04:44 +0800 Committer: Ben Hutchings <ben at decadent.org.uk> CommitDate: Sat, 28 Mar 2020 21:42:54 +0000 [klibc] dash: [BUILTIN] Remove getintmax in printf [ dash commit 33b1ccbdab76baf9acad6f57d7e7a18e74c02cca ] This patch removes getintmax and moves its functionality into getuintmax in order to reduce code duplication. Signed-off-by: Herbert Xu <herbert at gondor.apana.org.au> [bwh: Adjust context for klibc] Signed-off-by: Ben Hutchings <ben at decadent.org.uk> --- usr/dash/bltin/printf.c | 45 +++++++++++---------------------------------- 1 file changed, 11 insertions(+), 34 deletions(-) diff --git a/usr/dash/bltin/printf.c b/usr/dash/bltin/printf.c index 5cd34a19..b439a3bb 100644 --- a/usr/dash/bltin/printf.c +++ b/usr/dash/bltin/printf.c @@ -46,8 +46,7 @@ static int getchr(void); #ifdef HAVE_STRTOD static double getdouble(void); #endif -static intmax_t getintmax(void); -static uintmax_t getuintmax(void); +static uintmax_t getuintmax(int); static char *getstr(void); static char *mklong(const char *, const char *); static void check_conversion(const char *, const char *); @@ -181,14 +180,14 @@ pc: /* skip to field width */ fmt += strspn(fmt, SKIP1); if (*fmt == '*') - *param++ = getintmax(); + *param++ = getuintmax(1); /* skip to possible '.', get following precision */ fmt += strspn(fmt, SKIP2); if (*fmt == '.') ++fmt; if (*fmt == '*') - *param++ = getintmax(); + *param++ = getuintmax(1); fmt += strspn(fmt, SKIP2); @@ -222,18 +221,18 @@ pc: } case 'd': case 'i': { - intmax_t p = getintmax(); - char *f = mklong(start, fmt); - PF(f, p); + uintmax_t p = getuintmax(1); + start = mklong(start, fmt); + PF(start, p); break; } case 'o': case 'u': case 'x': case 'X': { - uintmax_t p = getuintmax(); - char *f = mklong(start, fmt); - PF(f, p); + uintmax_t p = getuintmax(0); + start = mklong(start, fmt); + PF(start, p); break; } #ifdef HAVE_STRTOD @@ -408,30 +407,8 @@ getstr(void) return val; } -static intmax_t -getintmax(void) -{ - intmax_t val = 0; - char *cp, *ep; - - cp = *gargv; - if (cp == NULL) - goto out; - gargv++; - - val = (unsigned char) cp[1]; - if (*cp == '\"' || *cp == '\'') - goto out; - - errno = 0; - val = strtoimax(cp, &ep, 0); - check_conversion(cp, ep); -out: - return val; -} - static uintmax_t -getuintmax(void) +getuintmax(int sign) { uintmax_t val = 0; char *cp, *ep; @@ -446,7 +423,7 @@ getuintmax(void) goto out; errno = 0; - val = strtoumax(cp, &ep, 0); + val = sign ? strtoimax(cp, &ep, 0) : strtoumax(cp, &ep, 0); check_conversion(cp, ep); out: return val;
Maybe Matching Threads
- [klibc:update-dash] [BUILTIN] Remove getintmax in printf
- [klibc:update-dash] dash: Fix some cosmetic differences from upstream dash
- [klibc:update-dash] dash: Fix some cosmetic differences from upstream dash
- [klibc:update-dash] builtin: Reject malformed printf specifications with digits after '*'
- [klibc:update-dash] dash: builtin: Reject malformed printf specifications with digits after '*'