mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2026-05-06 06:46:29 -04:00
audioconvert: use strbuf to construct the channel names
This handles overflow and errors correctly, unlike snprintf which might return -1 or the size that would have been written if truncated, causing overwrite later.
This commit is contained in:
parent
bceaf1a212
commit
195c048d1c
1 changed files with 4 additions and 2 deletions
|
|
@ -2266,10 +2266,12 @@ static void set_volume(struct impl *this)
|
||||||
|
|
||||||
static char *format_position(char *str, size_t len, uint32_t channels, uint32_t *position)
|
static char *format_position(char *str, size_t len, uint32_t channels, uint32_t *position)
|
||||||
{
|
{
|
||||||
uint32_t i, idx = 0;
|
uint32_t i;
|
||||||
char buf[8];
|
char buf[8];
|
||||||
|
struct spa_strbuf b;
|
||||||
|
spa_strbuf_init(&b, str, len);
|
||||||
for (i = 0; i < channels; i++)
|
for (i = 0; i < channels; i++)
|
||||||
idx += snprintf(str + idx, len - idx, "%s%s", i == 0 ? "" : " ",
|
spa_strbuf_append(&b, "%s%s", i == 0 ? "" : " ",
|
||||||
spa_type_audio_channel_make_short_name(position[i],
|
spa_type_audio_channel_make_short_name(position[i],
|
||||||
buf, sizeof(buf), "UNK"));
|
buf, sizeof(buf), "UNK"));
|
||||||
return str;
|
return str;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue