aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-10-30 23:24:18 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-10-30 23:24:18 +0100
commit93ef5dd640ef41edc72c80fa59c7cc9427b5945b (patch)
treeed0a5c83cea2a34a7603cb5ff565fc82f92f31ea
parent63d053d8c3e991d86cbacccb9ba6ff03aedee5cd (diff)
downloadbusybox-w32-93ef5dd640ef41edc72c80fa59c7cc9427b5945b.tar.gz
busybox-w32-93ef5dd640ef41edc72c80fa59c7cc9427b5945b.tar.bz2
busybox-w32-93ef5dd640ef41edc72c80fa59c7cc9427b5945b.zip
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 <vda.linux@googlemail.com>
-rw-r--r--coreutils/printf.c8
-rw-r--r--libbb/bb_strtonum.c2
2 files changed, 9 insertions, 1 deletions
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)
95 95
96static void FAST_FUNC conv_strtoull(const char *arg, void *result) 96static void FAST_FUNC conv_strtoull(const char *arg, void *result)
97{ 97{
98 /* Allow leading '+' - bb_strtoull() by itself does not allow it,
99 * and probably shouldn't (other callers might require purely numeric
100 * inputs to be allowed.
101 */
102 if (arg[0] == '+')
103 arg++;
98 *(unsigned long long*)result = bb_strtoull(arg, NULL, 0); 104 *(unsigned long long*)result = bb_strtoull(arg, NULL, 0);
99 /* both coreutils 6.10 and bash 3.2: 105 /* both coreutils 6.10 and bash 3.2:
100 * $ printf '%x\n' -2 106 * $ printf '%x\n' -2
@@ -107,6 +113,8 @@ static void FAST_FUNC conv_strtoull(const char *arg, void *result)
107} 113}
108static void FAST_FUNC conv_strtoll(const char *arg, void *result) 114static void FAST_FUNC conv_strtoll(const char *arg, void *result)
109{ 115{
116 if (arg[0] == '+')
117 arg++;
110 *(long long*)result = bb_strtoll(arg, NULL, 0); 118 *(long long*)result = bb_strtoll(arg, NULL, 0);
111} 119}
112static void FAST_FUNC conv_strtod(const char *arg, void *result) 120static 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)
81 /* Check for the weird "feature": 81 /* Check for the weird "feature":
82 * a "-" string is apparently a valid "number" for strto[u]l[l]! 82 * a "-" string is apparently a valid "number" for strto[u]l[l]!
83 * It returns zero and errno is 0! :( */ 83 * It returns zero and errno is 0! :( */
84 first = (arg[0] != '-' && arg[0] != '+' ? arg[0] : arg[1]); 84 first = (arg[0] != '-' ? arg[0] : arg[1]);
85 if (!isalnum(first)) return ret_ERANGE(); 85 if (!isalnum(first)) return ret_ERANGE();
86 86
87 errno = 0; 87 errno = 0;