[Bug c/65158] printf attribute error reporting assumes single-byte characters

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Sat Sep 15 16:25:00 GMT 2018


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65158

--- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> ---
(In reply to Manuel López-Ibáñez from comment #3)
> void foo(void) {
>     __builtin_printf("%ñ%中");
>     __builtin_printf ("%\x1B$B"); /* Taken from PR33748 */
>  }
> 
> <source>: In function 'void foo()':
> <source>:2:22: warning: unknown conversion type character '\xc3' in format
> [-Wformat=]
> 2 |     __builtin_printf("%ñ%中");
>   |                      ^~~~~~~~~
> <source>:2:22: warning: unknown conversion type character '\xe4' in format
> [-Wformat=]
> <source>:3:23: warning: unknown conversion type character '\x1b' in format
> [-Wformat=]
> 3 |     __builtin_printf ("%\x1B$B");
>   |                       ^~~~~~~~~
> 
> Note that ñ and 中 are multi-byte but the message only shows one byte.

What follows the percent sign must one of the C or POSIX conversion specifiers
(after any optional flags etc.) and those are all single byte characters in
most (all?) charsets.  In %x\x1B$B" (in the test case from PR33748) the \x1B
character is the beginning of an ISO-2022 escape sequence and not a valid
conversion specifier so I think it's fine, even correct, to only consider it as
the (invalid) conversion specifier, print it in the warning, and restart
parsing with the byte after it.  Treating what follows % as a sequence of
multibyte characters could otherwise throw off the remaining parsing.


More information about the Gcc-bugs mailing list