From 7105e4afddbf47b494accce40e2a701b8833e6ce Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Thu, 16 Dec 2021 11:19:03 +0000 Subject: printf: allow 0 as a flag and allow multiple flags The '%' character in a format specification may be followed by one or more flags from the list "+- #0". BusyBox printf didn't support the '0' flag or allow multiple flags to be provided. As a result the formats '%0*d' and '%0 d' were considered to be invalid. The lack of support for '0' was pointed out by Andrew Snyder on the musl mailing list: https://www.openwall.com/lists/musl/2021/12/14/2 function old new delta printf_main 860 891 +31 .rodata 99281 99282 +1 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 32/0) Total: 32 bytes Signed-off-by: Ron Yorston Signed-off-by: Denys Vlasenko --- testsuite/printf.tests | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'testsuite') diff --git a/testsuite/printf.tests b/testsuite/printf.tests index 050edef71..728bbf4bf 100755 --- a/testsuite/printf.tests +++ b/testsuite/printf.tests @@ -143,4 +143,14 @@ testing "printf aborts on %r" \ "printf: %r: invalid format\n""1\n" \ "" "" +testing "printf treats leading 0 as flag" \ + "${bb}printf '%0*d\n' 2 1 2>&1; echo \$?" \ + "01\n""0\n" \ + "" "" + +testing "printf handles multiple flags" \ + "${bb}printf '%0 d\n' 2 2>&1; echo \$?" \ + " 2\n""0\n" \ + "" "" + exit $FAILCOUNT -- cgit v1.2.1