Re: [PATCH v2 4/6] vsnprintf: Mark binary printing functions with __printf() attribute

From: Steven Rostedt
Date: Mon Mar 24 2025 - 15:20:35 EST


On Fri, 21 Mar 2025 16:40:50 +0200
Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx> wrote:

> Binary printf() functions are using printf() type of format, and compiler
> is not happy about them as is:
>
> lib/vsprintf.c:3130:47: error: function ‘vbin_printf’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
> lib/vsprintf.c:3298:33: error: function ‘bstr_printf’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]

BTW, I find it disturbing that the compiler is set to "error" on a warning
that "might be a candidate". What happens if it is not? We have to play
games to quiet it.

Adding __printf() attributes to stubs seems to be a case of the compiler
causing more problems than its worth :-/

I honestly hate this error on warning because it causes real pain when
debugging. There's a lot of times I don't know if the value is long or long
long, and when I get it wrong, my printk() causes the build to fail. It's
especially annoying when both long and long long are the same size!

Fixing theses stupid errors takes a non trivial amount of time away from
actual debugging.

-- Steve


>
> Fix the compilation errors by adding __printf() attribute.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>