mbox series

[00/13] ALSA: Fix -Wformat-truncation warnings

Message ID 20230915082802.28684-1-tiwai@suse.de
Headers show
Series ALSA: Fix -Wformat-truncation warnings | expand

Message

Takashi Iwai Sept. 15, 2023, 8:27 a.m. UTC
Hi,

the recent change introduced -Wformat-truncation for the build with
W=1, and this leads to many warnings.  Most of them are
false-positive, and they can be suppressed by replacing snprintf()
with scnprintf() for explicit truncation.  A couple of other code
deserve for a slight improvement.


Takashi

===

Takashi Iwai (13):
  ALSA: seq: ump: Fix -Wformat-truncation warning
  ALSA: seq: midi: Fix -Wformat-truncation warning
  ALSA: usb-audio: scarlett_gen2: Fix -Wformat-truncation warning
  ALSA: caiaq: Fix -Wformat-truncation warning
  ALSA: sscape: Fix -Wformat-truncation warning
  ALSA: cs4236: Fix -Wformat-truncation warning
  ALSA: es1688: Fix -Wformat-truncation warning
  ALSA: opti9x: Fix -Wformat-truncation warning
  ALSA: xen: Fix -Wformat-truncation warning
  ALSA: firewire: Fix -Wformat-truncation warning for longname string
  ALSA: firewire: Fix -Wformat-truncation warning for MIDI stream names
  ALSA: cmipci: Fix -Wformat-truncation warning
  ALSA: hda: generic: Check potential mixer name string truncation

 sound/core/seq/seq_midi.c                 |  4 ++--
 sound/core/seq/seq_ump_client.c           |  2 +-
 sound/firewire/bebob/bebob_midi.c         |  6 +++---
 sound/firewire/dice/dice-midi.c           |  4 ++--
 sound/firewire/digi00x/digi00x-midi.c     | 14 +++++++-------
 sound/firewire/fireface/ff-midi.c         |  4 ++--
 sound/firewire/fireworks/fireworks.c      | 10 +++++-----
 sound/firewire/fireworks/fireworks_midi.c |  4 ++--
 sound/firewire/motu/motu-midi.c           |  4 ++--
 sound/firewire/oxfw/oxfw-midi.c           |  6 +++---
 sound/firewire/oxfw/oxfw.c                | 10 +++++-----
 sound/firewire/tascam/tascam-midi.c       | 12 ++++++------
 sound/isa/cs423x/cs4236.c                 | 14 +++++++-------
 sound/isa/es1688/es1688.c                 |  6 +++---
 sound/isa/opti9xx/miro.c                  |  8 ++++----
 sound/isa/opti9xx/opti92x-ad1848.c        | 16 ++++++++--------
 sound/isa/sscape.c                        |  2 +-
 sound/pci/cmipci.c                        |  8 +++++---
 sound/pci/hda/hda_generic.c               |  6 +++++-
 sound/usb/caiaq/device.c                  |  2 +-
 sound/usb/mixer_scarlett_gen2.c           |  4 ++--
 sound/xen/xen_snd_front_cfg.c             |  2 +-
 22 files changed, 77 insertions(+), 71 deletions(-)

Comments

Takashi Sakamoto Sept. 15, 2023, 10:13 a.m. UTC | #1
Hi,

On Fri, Sep 15, 2023 at 10:27:59AM +0200, Takashi Iwai wrote:
> 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.
> 
> Signed-off-by: Takashi Iwai <tiwai@suse.de>
> ---
>  sound/firewire/fireworks/fireworks.c | 10 +++++-----
>  sound/firewire/oxfw/oxfw.c           | 10 +++++-----
>  2 files changed, 10 insertions(+), 10 deletions(-)

Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Tested-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>

> diff --git a/sound/firewire/fireworks/fireworks.c b/sound/firewire/fireworks/fireworks.c
> index dd4298876ac0..e3ed4e094ccd 100644
> --- a/sound/firewire/fireworks/fireworks.c
> +++ b/sound/firewire/fireworks/fireworks.c
> @@ -93,11 +93,11 @@ get_hardware_info(struct snd_efw *efw)
>  	strcpy(efw->card->driver, "Fireworks");
>  	strcpy(efw->card->shortname, hwinfo->model_name);
>  	strcpy(efw->card->mixername, hwinfo->model_name);
> -	snprintf(efw->card->longname, sizeof(efw->card->longname),
> -		 "%s %s v%s, GUID %08x%08x at %s, S%d",
> -		 hwinfo->vendor_name, hwinfo->model_name, version,
> -		 hwinfo->guid_hi, hwinfo->guid_lo,
> -		 dev_name(&efw->unit->device), 100 << fw_dev->max_speed);
> +	scnprintf(efw->card->longname, sizeof(efw->card->longname),
> +		  "%s %s v%s, GUID %08x%08x at %s, S%d",
> +		  hwinfo->vendor_name, hwinfo->model_name, version,
> +		  hwinfo->guid_hi, hwinfo->guid_lo,
> +		  dev_name(&efw->unit->device), 100 << fw_dev->max_speed);
>  
>  	if (hwinfo->flags & BIT(FLAG_RESP_ADDR_CHANGABLE))
>  		efw->resp_addr_changable = true;
> diff --git a/sound/firewire/oxfw/oxfw.c b/sound/firewire/oxfw/oxfw.c
> index 63d40f1a914f..241a697ce26b 100644
> --- a/sound/firewire/oxfw/oxfw.c
> +++ b/sound/firewire/oxfw/oxfw.c
> @@ -108,11 +108,11 @@ static int name_card(struct snd_oxfw *oxfw, const struct ieee1394_device_id *ent
>  	strcpy(oxfw->card->mixername, m);
>  	strcpy(oxfw->card->shortname, m);
>  
> -	snprintf(oxfw->card->longname, sizeof(oxfw->card->longname),
> -		 "%s %s (OXFW%x %04x), GUID %08x%08x at %s, S%d",
> -		 v, m, firmware >> 20, firmware & 0xffff,
> -		 fw_dev->config_rom[3], fw_dev->config_rom[4],
> -		 dev_name(&oxfw->unit->device), 100 << fw_dev->max_speed);
> +	scnprintf(oxfw->card->longname, sizeof(oxfw->card->longname),
> +		  "%s %s (OXFW%x %04x), GUID %08x%08x at %s, S%d",
> +		  v, m, firmware >> 20, firmware & 0xffff,
> +		  fw_dev->config_rom[3], fw_dev->config_rom[4],
> +		  dev_name(&oxfw->unit->device), 100 << fw_dev->max_speed);
>  end:
>  	return err;
>  }
> -- 
> 2.35.3

Thanks

Takashi Sakamoto