* 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.
---
src/printf.c | 2 +-
tests/printf/printf.sh | 11 ++++++++++-
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/src/printf.c b/src/printf.c
index 4ce54a231..ad9f5432f 100644
--- a/src/printf.c
+++ b/src/printf.c
@@ -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 \
{ \
diff --git a/tests/printf/printf.sh b/tests/printf/printf.sh
index 305f5c171..06558ee94 100755
--- a/tests/printf/printf.sh
+++ b/tests/printf/printf.sh
@@ -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
--
2.56.0