From: Denys Vlasenko Date: Tue, 30 Oct 2018 22:24:18 +0000 (+0100) Subject: printf: fix printf "%u\n" +18446744073709551614 X-Git-Tag: 1_30_0~424 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=93ef5dd640ef41edc72c80fa59c7cc9427b5945b;p=oweals%2Fbusybox.git printf: fix printf "%u\n" +18446744073709551614 function old new delta conv_strtoll 19 32 +13 conv_strtoull 49 61 +12 bb_strtoll 89 84 -5 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 25/-5) Total: 20 bytes Signed-off-by: Denys Vlasenko --- diff --git a/coreutils/printf.c b/coreutils/printf.c index b2429c5cf..67d3b2eda 100644 --- a/coreutils/printf.c +++ b/coreutils/printf.c @@ -95,6 +95,12 @@ static int multiconvert(const char *arg, void *result, converter convert) static void FAST_FUNC conv_strtoull(const char *arg, void *result) { + /* Allow leading '+' - bb_strtoull() by itself does not allow it, + * and probably shouldn't (other callers might require purely numeric + * inputs to be allowed. + */ + if (arg[0] == '+') + arg++; *(unsigned long long*)result = bb_strtoull(arg, NULL, 0); /* both coreutils 6.10 and bash 3.2: * $ printf '%x\n' -2 @@ -107,6 +113,8 @@ static void FAST_FUNC conv_strtoull(const char *arg, void *result) } static void FAST_FUNC conv_strtoll(const char *arg, void *result) { + if (arg[0] == '+') + arg++; *(long long*)result = bb_strtoll(arg, NULL, 0); } static void FAST_FUNC conv_strtod(const char *arg, void *result) diff --git a/libbb/bb_strtonum.c b/libbb/bb_strtonum.c index cb70f1053..2185017b0 100644 --- a/libbb/bb_strtonum.c +++ b/libbb/bb_strtonum.c @@ -81,7 +81,7 @@ long long FAST_FUNC bb_strtoll(const char *arg, char **endp, int base) /* Check for the weird "feature": * a "-" string is apparently a valid "number" for strto[u]l[l]! * It returns zero and errno is 0! :( */ - first = (arg[0] != '-' && arg[0] != '+' ? arg[0] : arg[1]); + first = (arg[0] != '-' ? arg[0] : arg[1]); if (!isalnum(first)) return ret_ERANGE(); errno = 0;