Re: [PATCH] ALSA: info: Use snprintf() in snd_info_card_create()
From: Thorsten Blum
Date: Sat Nov 07 2026 - 08:57:28 EST
On Sat, Nov 07, 2026 at 02:44:57PM +0100, Takashi Iwai wrote:
> On Sat, 07 Nov 2026 14:04:33 +0100,
> Thorsten Blum wrote:
> >
> > On Sat, Nov 07, 2026 at 10:14:38AM +0100, Takashi Iwai wrote:
> > > On Sat, 07 Nov 2026 01:43:37 +0100,
> > > Thorsten Blum wrote:
> > > >
> > > > While the current code works correctly, replace the unbounded sprintf()
> > > > with snprintf() to bound the formatted string to the str buffer.
> > > >
> > > > Signed-off-by: Thorsten Blum <blum@xxxxxxxxxx>
> > >
> > > Shouldn't we use scnprintf() instead? Otherwise it may lead to a
> > > compiler warning.
> >
> > The only difference between snprintf() and scnprintf() is the return
> > value, which is unused here. Both are correct and shouldn't trigger a
> > warning.
>
> Well, not really. For this particular patch, it doesn't make
> difference, but in some cases (like the use with %s), snprintf()
> causes a spurious compile warning with W=1. e.g. try below.
Agreed, although that's a different use case from my patch.
I don't see a warning when compiling my patch with W=1, but I'm happy to
switch to scnprintf() if you prefer.