printf: quote the ignored characters in the warning

* src/printf.c (STRTOX): Add a call to quote when printing the ignored
characters.
* tests/printf/printf.sh: Adjust an existing test case. Add another
quoting test case.

Discovered by Anthropic's OSS Scanner, as bug ANT-2026-I9I24ON7.
This commit is contained in:
Collin Funk committed 2026-10-27 18:16:03 -07:00
1 parent c242899118
commit 9e804edddb
2 files changed
+11 -2

No files matched your search

+1 -1
View File
@@ -178,7 +178,7 @@ FUNC_NAME (char const *s) \
printf is ignoring those characters. If POSIXLY_CORRECT *is* \
set, then don't give the warning. */ \
if (*++s != 0 && !posixly_correct) \
error (0, 0, _(cfcc_msg), s); \
error (0, 0, _(cfcc_msg), quote (s)); \
} \
else \
{ \
+10 -1
View File
@@ -125,8 +125,9 @@ EOF
# Map that output to the more common expected output.
sed 's/: Invalid.*/: expected a numeric value/' err > k && mv k err
ignore='character(s) following character constant have been ignored'
cat <<EOF > exp_err
printf: warning: ": character(s) following character constant have been ignored
printf: warning: '"': $ignore
printf: '"': expected a numeric value
printf: 'a': expected a numeric value
EOF
@@ -134,6 +135,14 @@ EOF
compare exp out || fail=1
compare exp_err err || fail=1
NL='
'
echo 97 > exp || framework_failure_
echo "printf: warning: 'b\nc': $ignore" >exp-err || framework_failure_
$prog '%d\n' '"ab'"$NL"'c' >out 2>err || fail=1
compare exp out || fail=1
compare exp-err err || fail=1
# Ensure large field widths and precisions produce fully padded output
$prog '%70000d' 1 > out || fail=1
test "$(wc -c < out)" = 70000 || fail=1