aboutsummaryrefslogtreecommitdiff
path: root/coreutils/printf.c
diff options
context:
space:
mode:
Diffstat (limited to 'coreutils/printf.c')
-rw-r--r--coreutils/printf.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/coreutils/printf.c b/coreutils/printf.c
index a666ff7ac..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)
@@ -191,6 +199,7 @@ static void print_direc(char *format, unsigned fmt_length,
191 if (have_width - 1 == have_prec) 199 if (have_width - 1 == have_prec)
192 have_width = NULL; 200 have_width = NULL;
193 201
202 /* multiconvert sets errno = 0, but %s needs it cleared */
194 errno = 0; 203 errno = 0;
195 204
196 switch (format[fmt_length - 1]) { 205 switch (format[fmt_length - 1]) {
@@ -199,7 +208,7 @@ static void print_direc(char *format, unsigned fmt_length,
199 break; 208 break;
200 case 'd': 209 case 'd':
201 case 'i': 210 case 'i':
202 llv = my_xstrtoll(argument); 211 llv = my_xstrtoll(skip_whitespace(argument));
203 print_long: 212 print_long:
204 if (!have_width) { 213 if (!have_width) {
205 if (!have_prec) 214 if (!have_prec)
@@ -217,7 +226,7 @@ static void print_direc(char *format, unsigned fmt_length,
217 case 'u': 226 case 'u':
218 case 'x': 227 case 'x':
219 case 'X': 228 case 'X':
220 llv = my_xstrtoull(argument); 229 llv = my_xstrtoull(skip_whitespace(argument));
221 /* cheat: unsigned long and long have same width, so... */ 230 /* cheat: unsigned long and long have same width, so... */
222 goto print_long; 231 goto print_long;
223 case 's': 232 case 's':