modules: convert snprintf to strbuf

Use spa_strbuf instead of snprintf to handle errors better.
This commit is contained in:
Wim Taymans 2026-05-06 13:35:09 +02:00
parent 2c4dc2d22f
commit 51b635cc98
4 changed files with 25 additions and 16 deletions

View file

@ -288,13 +288,15 @@ void audioinfo_to_properties(struct spa_audio_info_raw *info, struct pw_properti
if (info->rate)
pw_properties_setf(props, SPA_KEY_AUDIO_RATE, "%u", info->rate);
if (info->channels) {
char *s, *p, pos[8];
char *s, pos[8];
struct spa_strbuf b;
pw_properties_setf(props, SPA_KEY_AUDIO_CHANNELS, "%u", info->channels);
p = s = alloca(info->channels * 8);
s = alloca(info->channels * 8);
spa_strbuf_init(&b, s, info->channels * 8);
for (i = 0; i < info->channels; i++)
p += spa_scnprintf(p, 8, "%s%s", i == 0 ? "" : ", ",
spa_strbuf_append(&b, "%s%s", i == 0 ? "" : ", ",
channel_id2name(info->position[i], pos, sizeof(pos)));
pw_properties_setf(props, SPA_KEY_AUDIO_POSITION, "[ %s ]", s);
}