summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--coreutils/printf.c5
-rw-r--r--libbb/bb_strtonum.c2
-rwxr-xr-xtestsuite/printf.tests33
3 files changed, 37 insertions, 3 deletions
diff --git a/coreutils/printf.c b/coreutils/printf.c
index a666ff7..b2429c5 100644
--- a/coreutils/printf.c
+++ b/coreutils/printf.c
@@ -191,6 +191,7 @@ static void print_direc(char *format, unsigned fmt_length,
if (have_width - 1 == have_prec)
have_width = NULL;
+ /* multiconvert sets errno = 0, but %s needs it cleared */
errno = 0;
switch (format[fmt_length - 1]) {
@@ -199,7 +200,7 @@ static void print_direc(char *format, unsigned fmt_length,
break;
case 'd':
case 'i':
- llv = my_xstrtoll(argument);
+ llv = my_xstrtoll(skip_whitespace(argument));
print_long:
if (!have_width) {
if (!have_prec)
@@ -217,7 +218,7 @@ static void print_direc(char *format, unsigned fmt_length,
case 'u':
case 'x':
case 'X':
- llv = my_xstrtoull(argument);
+ llv = my_xstrtoull(skip_whitespace(argument));
/* cheat: unsigned long and long have same width, so... */
goto print_long;
case 's':
diff --git a/libbb/bb_strtonum.c b/libbb/bb_strtonum.c
index 2185017..cb70f10 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[1]);
+ first = (arg[0] != '-' && arg[0] != '+' ? arg[0] : arg[1]);
if (!isalnum(first)) return ret_ERANGE();
errno = 0;
diff --git a/testsuite/printf.tests b/testsuite/printf.tests
index 963ded9..34a6592 100755
--- a/testsuite/printf.tests
+++ b/testsuite/printf.tests
@@ -79,6 +79,39 @@ testing "printf understands %Ld" \
"-5\n""0\n" \
"" ""
+testing "printf handles positive numbers for %d" \
+ "${bb}printf '%d\n' 3 +3 ' 3' ' +3' 2>&1; echo \$?" \
+ "3\n"\
+"3\n"\
+"3\n"\
+"3\n""0\n" \
+ "" ""
+
+testing "printf handles positive numbers for %i" \
+ "${bb}printf '%i\n' 3 +3 ' 3' ' +3' 2>&1; echo \$?" \
+ "3\n"\
+"3\n"\
+"3\n"\
+"3\n""0\n" \
+ "" ""
+
+testing "printf handles positive numbers for %x" \
+ "${bb}printf '%x\n' 42 +42 ' 42' ' +42' 2>&1; echo \$?" \
+ "2a\n"\
+"2a\n"\
+"2a\n"\
+"2a\n""0\n" \
+ "" ""
+
+testing "printf handles positive numbers for %f" \
+ "${bb}printf '%0.3f\n' .42 +.42 ' .42' ' +.42' 2>&1; echo \$?" \
+ "0.420\n"\
+"0.420\n"\
+"0.420\n"\
+"0.420\n""0\n" \
+ "" ""
+
+
# "FIXED" now to act compatibly
## We are "more correct" here than bash/coreutils: they happily print -2
## as if it is a huge unsigned number