From 9a5d7a063c8c7ad1f7b036282ea4d476e7065167 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 29 May 2022 18:11:34 -0500 Subject: [PATCH] Work around gratuitous musl deviation from glibc, adding tests. Although posix says strtol() _can_ return EINVAL for "", glibc doesn't, and the command line printf %d "" happily calls the result 0, so ignore the suprious error from musl. --- tests/printf.test | 3 ++- toys/posix/printf.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/printf.test b/tests/printf.test index 30525c6b..e9e2fe86 100755 --- a/tests/printf.test +++ b/tests/printf.test @@ -31,6 +31,8 @@ testing "%x" "$PRINTF '%x\n' 0x2a" "2a\n" "" "" testing "%d 42" "$PRINTF %d 42" "42" "" "" testing "%d 0x2a" "$PRINTF %d 0x2a" "42" "" "" testing "%d 052" "$PRINTF %d 052" "42" "" "" +testing "%d none" "$PRINTF %d" "0" "" "" +testing "%d null" "$PRINTF %d ''" "0" "" "" testing "%s width precision" \ "$PRINTF '%3s,%.3s,%10s,%10.3s' abcde fghij klmno pqrst" \ @@ -46,7 +48,6 @@ testing "'%3c'" "$PRINTF '%3c' x" " x" "" "" testing "'%-3c'" "$PRINTF '%-3c' x" "x " "" "" testing "'%+d'" "$PRINTF '%+d' 5" "+5" "" "" - testing "'%5d%4d' 1 21 321 4321 54321" \ "$PRINTF '%5d%4d' 1 21 321 4321 54321" " 1 21 321432154321 0" "" "" testing "'%c %c' 78 79" "$PRINTF '%c %c' 78 79" "7 7" "" "" diff --git a/toys/posix/printf.c b/toys/posix/printf.c index 2cbf3035..eedd83e9 100644 --- a/toys/posix/printf.c +++ b/toys/posix/printf.c @@ -130,7 +130,7 @@ void printf_main(void) printf(toybuf, wp[0], wp[1], ld); } else error_exit("bad %%%c@%ld", c, (long)(f-*toys.optargs)); - if (end && (errno || *end)) perror_msg("bad %%%c %s", c, aa); + if (end && (*end || errno==ERANGE)) perror_msg("bad %%%c %s", c, aa); } } -- 2.39.2