mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2026-05-28 21:37:33 -04:00
avb: use safer strbuf to construct strings
This commit is contained in:
parent
8276d615ba
commit
b66614063d
1 changed files with 15 additions and 20 deletions
|
|
@ -89,36 +89,31 @@ static int avb_set_param(struct state *state, const char *k, const char *s)
|
||||||
|
|
||||||
static int position_to_string(struct channel_map *map, char *val, size_t len)
|
static int position_to_string(struct channel_map *map, char *val, size_t len)
|
||||||
{
|
{
|
||||||
uint32_t i, o = 0;
|
uint32_t i;
|
||||||
int r;
|
|
||||||
char pos[8];
|
char pos[8];
|
||||||
o += snprintf(val, len, "[ ");
|
struct spa_strbuf b;
|
||||||
|
|
||||||
|
spa_strbuf_init(&b, val, len);
|
||||||
|
spa_strbuf_append(&b, "[ ");
|
||||||
for (i = 0; i < map->channels; i++) {
|
for (i = 0; i < map->channels; i++) {
|
||||||
r = snprintf(val+o, len-o, "%s%s", i == 0 ? "" : ", ",
|
spa_strbuf_append(&b, "%s%s", i == 0 ? "" : ", ",
|
||||||
spa_type_audio_channel_make_short_name(map->pos[i],
|
spa_type_audio_channel_make_short_name(map->pos[i],
|
||||||
pos, sizeof(pos), "UNK"));
|
pos, sizeof(pos), "UNK"));
|
||||||
if (r < 0 || o + r >= len)
|
|
||||||
return -ENOSPC;
|
|
||||||
o += r;
|
|
||||||
}
|
}
|
||||||
if (len > o)
|
spa_strbuf_append(&b, " ]");
|
||||||
o += snprintf(val+o, len-o, " ]");
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int uint32_array_to_string(uint32_t *vals, uint32_t n_vals, char *val, size_t len)
|
static int uint32_array_to_string(uint32_t *vals, uint32_t n_vals, char *val, size_t len)
|
||||||
{
|
{
|
||||||
uint32_t i, o = 0;
|
uint32_t i;
|
||||||
int r;
|
struct spa_strbuf b;
|
||||||
o += snprintf(val, len, "[ ");
|
|
||||||
for (i = 0; i < n_vals; i++) {
|
spa_strbuf_init(&b, val, len);
|
||||||
r = snprintf(val+o, len-o, "%s%d", i == 0 ? "" : ", ", vals[i]);
|
spa_strbuf_append(&b, "[ ");
|
||||||
if (r < 0 || o + r >= len)
|
for (i = 0; i < n_vals; i++)
|
||||||
return -ENOSPC;
|
spa_strbuf_append(&b, "%s%d", i == 0 ? "" : ", ", vals[i]);
|
||||||
o += r;
|
spa_strbuf_append(&b, " ]");
|
||||||
}
|
|
||||||
if (len > o)
|
|
||||||
o += snprintf(val+o, len-o, " ]");
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue