Skip to contentSkip to conversation

ALSA: Yer more fix -Wformat-truncation warnings

PATCH New Takashi Iwai 1 participant 4 messages Sep 15, 2023 Sound

lore
Share & tools
lore
#0 lore raw

cover ALSA: Yer more fix -Wformat-truncation warnings

This is a few more similar patches covering the recent warnings by the -Wformat-truncation option.

Takashi

===

Takashi Iwai (3):
ALSA: ad1848: Fix -Wformat-truncation warning for longname string
ALSA: cs4231: Fix -Wformat-truncation warning for longname string
ALSA: riptide: Fix -Wformat-truncation warning for longname string

 sound/isa/ad1848/ad1848.c   | 12 ++++++------
 sound/isa/cs423x/cs4231.c   | 12 ++++++------
 sound/pci/riptide/riptide.c | 16 ++++++++--------
 3 files changed, 20 insertions(+), 20 deletions(-)
Signature · 1 line
2.35.3
#1 lore raw

PATCH 1/3 ALSA: ad1848: Fix -Wformat-truncation warning for longname string

The filling of card->longname can be gracefully truncated, as it's only informative. Use scnprintf() and suppress the superfluous compile warning with -Wformat-truncation.

---
 sound/isa/ad1848/ad1848.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
sound/isa/ad1848/ad1848.c +6 -6
index c471ac2aa450..401d8df28d87 100644
@@ -96,13 +96,13 @@ static int snd_ad1848_probe(struct device *dev, unsigned int n)
 	strscpy(card->shortname, chip->pcm->name, sizeof(card->shortname));
 
 	if (!thinkpad[n])
-		snprintf(card->longname, sizeof(card->longname),
-			 "%s at 0x%lx, irq %d, dma %d",
-			 chip->pcm->name, chip->port, irq[n], dma1[n]);
+		scnprintf(card->longname, sizeof(card->longname),
+			  "%s at 0x%lx, irq %d, dma %d",
+			  chip->pcm->name, chip->port, irq[n], dma1[n]);
 	else
-		snprintf(card->longname, sizeof(card->longname),
-			 "%s at 0x%lx, irq %d, dma %d [Thinkpad]",
-			 chip->pcm->name, chip->port, irq[n], dma1[n]);
+		scnprintf(card->longname, sizeof(card->longname),
+			  "%s at 0x%lx, irq %d, dma %d [Thinkpad]",
+			  chip->pcm->name, chip->port, irq[n], dma1[n]);
 
 	error = snd_card_register(card);
 	if (error < 0)
Signature · 1 line
2.35.3
#2 lore raw

PATCH 2/3 ALSA: cs4231: Fix -Wformat-truncation warning for longname string

In reply to Takashi Iwai

The filling of card->longname can be gracefully truncated, as it's only informative. Use scnprintf() and suppress the superfluous compile warning with -Wformat-truncation.

---
 sound/isa/cs423x/cs4231.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
sound/isa/cs423x/cs4231.c +6 -6
index 1e8923385366..c87be4be6df1 100644
@@ -98,13 +98,13 @@ static int snd_cs4231_probe(struct device *dev, unsigned int n)
 	strscpy(card->shortname, chip->pcm->name, sizeof(card->shortname));
 
 	if (dma2[n] < 0)
-		snprintf(card->longname, sizeof(card->longname),
-			 "%s at 0x%lx, irq %d, dma %d",
-			 chip->pcm->name, chip->port, irq[n], dma1[n]);
+		scnprintf(card->longname, sizeof(card->longname),
+			  "%s at 0x%lx, irq %d, dma %d",
+			  chip->pcm->name, chip->port, irq[n], dma1[n]);
 	else
-		snprintf(card->longname, sizeof(card->longname),
-			 "%s at 0x%lx, irq %d, dma %d&%d",
-			 chip->pcm->name, chip->port, irq[n], dma1[n], dma2[n]);
+		scnprintf(card->longname, sizeof(card->longname),
+			  "%s at 0x%lx, irq %d, dma %d&%d",
+			  chip->pcm->name, chip->port, irq[n], dma1[n], dma2[n]);
 
 	error = snd_wss_mixer(chip);
 	if (error < 0)
Signature · 1 line
2.35.3
#3 lore raw

PATCH 3/3 ALSA: riptide: Fix -Wformat-truncation warning for longname string

In reply to Takashi Iwai

The filling of card->longname can be gracefully truncated, as it's only informative. Use scnprintf() and suppress the superfluous compile warning with -Wformat-truncation.

---
 sound/pci/riptide/riptide.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
sound/pci/riptide/riptide.c +8 -8
index b37c877c2c16..9dee0345f22c 100644
@@ -2105,15 +2105,15 @@ __snd_card_riptide_probe(struct pci_dev *pci, const struct pci_device_id *pci_id
 	strcpy(card->driver, "RIPTIDE");
 	strcpy(card->shortname, "Riptide");
 #ifdef SUPPORT_JOYSTICK
-	snprintf(card->longname, sizeof(card->longname),
-		 "%s at 0x%lx, irq %i mpu 0x%x opl3 0x%x gameport 0x%x",
-		 card->shortname, chip->port, chip->irq, chip->mpuaddr,
-		 chip->opladdr, chip->gameaddr);
+	scnprintf(card->longname, sizeof(card->longname),
+		  "%s at 0x%lx, irq %i mpu 0x%x opl3 0x%x gameport 0x%x",
+		  card->shortname, chip->port, chip->irq, chip->mpuaddr,
+		  chip->opladdr, chip->gameaddr);
 #else
-	snprintf(card->longname, sizeof(card->longname),
-		 "%s at 0x%lx, irq %i mpu 0x%x opl3 0x%x",
-		 card->shortname, chip->port, chip->irq, chip->mpuaddr,
-		 chip->opladdr);
+	scnprintf(card->longname, sizeof(card->longname),
+		  "%s at 0x%lx, irq %i mpu 0x%x opl3 0x%x",
+		  card->shortname, chip->port, chip->irq, chip->mpuaddr,
+		  chip->opladdr);
 #endif
 	snd_riptide_proc_init(chip);
 	err = snd_card_register(card);
Signature · 1 line
2.35.3