1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-02-13 10:52:09 +02:00

printf: diagnose empty args correctly

Also, port better to macOS.
* src/printf.c (verify_numeric): Don’t assume that when s == end
then errno is zero; it is EINVAL on macOS, and POSIX allows this.
(print_direc): Treat missing arg as zero for numeric conversions,
and as an empty string for the others.
(print_formatted): Use null pointer, not an empty string,
to represent missing arg.
* tests/printf/printf.sh: Test empty and space widths and precisions.
This commit is contained in:
Paul Eggert
2024-11-18 18:19:54 -08:00
parent a665aa4f6d
commit 91e95f1f86
2 changed files with 29 additions and 13 deletions

View File

@@ -73,6 +73,11 @@ returns_ 1 $prog '%.*dx\n' $INT_OFLOW 0 >>out 2> /dev/null || fail=1
$prog '11 %*c\n' 2 x >>out || fail=1
returns_ 1 $prog '12 %*s\n' '' 'empty width' >>out 2>/dev/null || fail=1
returns_ 1 $prog '13 %*s\n' ' ' 'space width' >>out 2>/dev/null || fail=1
returns_ 1 $prog '14 %.*sx\n' '' 'empty precision' >>out 2>/dev/null || fail=1
returns_ 1 $prog '15 %.*sx\n' ' ' 'space precision' >>out 2>/dev/null || fail=1
returns_ 1 $prog '%#d\n' 0 >>out 2> /dev/null || fail=1
returns_ 1 $prog '%0s\n' 0 >>out 2> /dev/null || fail=1
@@ -93,6 +98,10 @@ cat <<\EOF > exp
9 0 x
10 0x
11 x
12 empty width
13 space width
14 x
15 x
EOF
compare exp out || fail=1