all printf variants: fix argument type handling for %c and %lc
authorRich Felker <dalias@aerifal.cx>
Mon, 12 Jun 2023 23:56:08 +0000 (19:56 -0400)
committerRich Felker <dalias@aerifal.cx>
Mon, 12 Jun 2023 23:56:08 +0000 (19:56 -0400)
commit3a23cd06b08054f81bf904c414e0d083a56248f2
tree14d8102a036b0283d51718ef2bf7f58bdfa36873
parentfa4a8abd06a401822cc8ba4e352a219544c0118d
all printf variants: fix argument type handling for %c and %lc

%c takes an argument of type int, not char, and %lc/%C takes an
argument of type wint_t (unsigned), not int.

for most cases, this makes no practical difference, but since wide
printf variants convert narrow %c format specifiers via btowc,
interpreting the promoted-to-int unsigned char value passed in as a
(signed, on most archs) char causes 255 to get collapsed to EOF and
interpreted as such by btowc.

this is only relevant in the byte-based C locale, so prior to commit
f22a9edaf8a6f2ca1d314d18b3785558279a5c03, there was no observable
distinction in behavior. for UTF-8, all bytes which might be negative
when interpreted as char are encoding errors when used with %c/btowc.
src/stdio/vfprintf.c
src/stdio/vfwprintf.c