ALSA: ump: Fix -Wformat-truncation warnings
PATCH 1/1 ALSA: ump: Fix -Wformat-truncation warnings
Filling the rawmidi name and substream name can be truncated, and this leads to spurious compiler warnings due to -Wformat-truncation. Although the truncation is the expected behavior, it'd be better to truncate the string within "(...)"
This patch puts the precision specifies to each %s for fitting the words within the size-limited strings.
--- sound/core/ump.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
sound/core/ump.c +2 -2
@@ -1157,7 +1157,7 @@ static void fill_substream_names(struct snd_ump_endpoint *ump,struct snd_rawmidi_substream *s;list_for_each_entry (s, &rmidi->streams[dir].substreams, list) -snprintf (s->name,sizeof (s->name),"Group %d (%s)" , +snprintf (s->name,sizeof (s->name),"Group %d (%.16s)" , ump->legacy_mapping[s->number] +1 , ump->info.name); }
@@ -1191,7 +1191,7 @@ int snd_ump_attach_legacy_rawmidi(struct snd_ump_endpoint *ump,if (output)snd_rawmidi_set_ops (rmidi,SNDRV_RAWMIDI_STREAM_OUTPUT , &snd_ump_legacy_output_ops); -snprintf (rmidi->name,sizeof (rmidi->name),"%s (MIDI 1.0)" , +snprintf (rmidi->name,sizeof (rmidi->name),"%.69s (MIDI 1.0)" , ump->info.name); rmidi->info_flags = ump->core.info_flags & ~SNDRV_RAWMIDI_INFO_UMP ; rmidi->ops = &snd_ump_legacy_ops;
Signature · 1 line
2.35.3
kernel test robot
build botkernel test robot noticed the following build warnings:
Hi Takashi,
kernel test robot noticed the following build warnings:
[auto build test WARNING on next-20230825]
[cannot apply to tiwai-sound/for-next tiwai-sound/for-linus v6.5-rc7 v6.5-rc6 v6.5-rc5 linus/master v6.5-rc7] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Takashi-Iwai/ALSA-ump-Fix-Wformat-truncation-warnings/20230825-231128 base: next-20230825 patch link: https://lore.kernel.org/r/20230825150915.1595-1-tiwai%40suse.de patch subject: [PATCH] ALSA: ump: Fix -Wformat-truncation warnings config: parisc-allyesconfig (https://download.01.org/0day-ci/archive/20230826/[email protected]/config) compiler: hppa-linux-gcc (GCC) 13.2.0 reproduce: (https://download.01.org/0day-ci/archive/20230826/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
sound/core/ump.c: In function 'snd_ump_attach_legacy_rawmidi':
>> sound/core/ump.c:1194:69: warning: 'snprintf' output may be truncated before the last format character [-Wformat-truncation=]
1194 | snprintf(rmidi->name, sizeof(rmidi->name), "%.69s (MIDI 1.0)",
| ^
sound/core/ump.c:1194:9: note: 'snprintf' output between 12 and 81 bytes into a destination of size 80
1194 | snprintf(rmidi->name, sizeof(rmidi->name), "%.69s (MIDI 1.0)",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1195 | ump->info.name);
| ~~~~~~~~~~~~~~~
>> sound/core/ump.c:1194:69: warning: 'snprintf' output may be truncated before the last format character [-Wformat-truncation=]
1194 | snprintf(rmidi->name, sizeof(rmidi->name), "%.69s (MIDI 1.0)",
| ^
sound/core/ump.c:1194:9: note: 'snprintf' output between 12 and 81 bytes into a destination of size 80
1194 | snprintf(rmidi->name, sizeof(rmidi->name), "%.69s (MIDI 1.0)",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1195 | ump->info.name);
| ~~~~~~~~~~~~~~~
>> sound/core/ump.c:1194:69: warning: 'snprintf' output may be truncated before the last format character [-Wformat-truncation=]
1194 | snprintf(rmidi->name, sizeof(rmidi->name), "%.69s (MIDI 1.0)",
| ^
sound/core/ump.c:1194:9: note: 'snprintf' output between 12 and 81 bytes into a destination of size 80
1194 | snprintf(rmidi->name, sizeof(rmidi->name), "%.69s (MIDI 1.0)",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1195 | ump->info.name);
| ~~~~~~~~~~~~~~~
>> sound/core/ump.c:1194:69: warning: 'snprintf' output may be truncated before the last format character [-Wformat-truncation=]
1194 | snprintf(rmidi->name, sizeof(rmidi->name), "%.69s (MIDI 1.0)",
| ^
sound/core/ump.c:1194:9: note: 'snprintf' output between 12 and 81 bytes into a destination of size 80
1194 | snprintf(rmidi->name, sizeof(rmidi->name), "%.69s (MIDI 1.0)",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1195 | ump->info.name);
| ~~~~~~~~~~~~~~~vim +/snprintf +1194 sound/core/ump.c
1163
1164 int snd_ump_attach_legacy_rawmidi(struct snd_ump_endpoint *ump,
1165 char *id, int device)
1166 {
1167 struct snd_rawmidi *rmidi;
1168 bool input, output;
1169 int err, num;
1170
1171 ump->out_cvts = kcalloc(SNDRV_UMP_MAX_GROUPS,
1172 sizeof(*ump->out_cvts), GFP_KERNEL);
1173 if (!ump->out_cvts)
1174 return -ENOMEM;
1175
1176 num = fill_legacy_mapping(ump);
1177
1178 input = ump->core.info_flags & SNDRV_RAWMIDI_INFO_INPUT;
1179 output = ump->core.info_flags & SNDRV_RAWMIDI_INFO_OUTPUT;
1180 err = snd_rawmidi_new(ump->core.card, id, device,
1181 output ? num : 0, input ? num : 0,
1182 &rmidi);
1183 if (err < 0) {
1184 kfree(ump->out_cvts);
1185 return err;
1186 }
1187
1188 if (input)
1189 snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT,
1190 &snd_ump_legacy_input_ops);
1191 if (output)
1192 snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT,
1193 &snd_ump_legacy_output_ops);
> 1194 snprintf(rmidi->name, sizeof(rmidi->name), "%.69s (MIDI 1.0)",
1195 ump->info.name);
1196 rmidi->info_flags = ump->core.info_flags & ~SNDRV_RAWMIDI_INFO_UMP;
1197 rmidi->ops = &snd_ump_legacy_ops;
1198 rmidi->private_data = ump;
1199 ump->legacy_rmidi = rmidi;
1200 if (input)
1201 fill_substream_names(ump, rmidi, SNDRV_RAWMIDI_STREAM_INPUT);
1202 if (output)
1203 fill_substream_names(ump, rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT);
1204
1205 ump_dbg(ump, "Created a legacy rawmidi #%d (%s)\n", device, id);
1206 return 0;
1207 }
1208 EXPORT_SYMBOL_GPL(snd_ump_attach_legacy_rawmidi);
1209 #endif /* CONFIG_SND_UMP_LEGACY_RAWMIDI */
1210
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki