mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Thorsten Blum <blum@kernel.org>
Cc: Takashi Iwai <tiwai@suse.de>, Jaroslav Kysela <perex@perex.cz>,
	Takashi Iwai <tiwai@suse.com>, Cen Zhang <zzzccc427@gmail.com>,
	Cezary Rojewski <cezary.rojewski@intel.com>,
	bui duc phuc <phucduc.bui@gmail.com>,
	linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ALSA: info: Use snprintf() in snd_info_card_create()
Date: Sat, 07 Nov 2026 14:44:57 +0100	[thread overview]
Message-ID: <87tslsycva.wl-tiwai@suse.de> (raw)
In-Reply-To: <au8h4SDC6fKaY7st@kernel.org>

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@kernel.org>
> > 
> > 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.


Takashi

--- a/sound/core/ump.c
+++ b/sound/core/ump.c
@@ -1369,7 +1369,7 @@ static void update_legacy_substreams(struct snd_ump_endpoint *ump,
 		name = ump->groups[idx].name;
 		if (!*name)
 			name = ump->core.name;
-		scnprintf(s->name, sizeof(s->name), "Group %d (%.16s)%s",
+		snprintf(s->name, sizeof(s->name), "Group %d (%.16s)%s",
 			  idx + 1, name,
 			  ump->groups[idx].active ? "" : " [Inactive]");
 		s->inactive = !ump->groups[idx].active;


  reply	other threads:[~2026-11-07 13:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-07  0:43 Thorsten Blum
2026-11-07  9:14 ` Takashi Iwai
2026-11-07 13:04   ` Thorsten Blum
2026-11-07 13:44     ` Takashi Iwai [this message]
2026-11-07 13:57       ` Thorsten Blum
2026-11-07 14:02         ` Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87tslsycva.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=blum@kernel.org \
    --cc=cezary.rojewski@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=phucduc.bui@gmail.com \
    --cc=tiwai@suse.com \
    --cc=zzzccc427@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®