spa: spa_json_get_string does not return the length

The returned string is null terminated.
This commit is contained in:
Wim Taymans 2021-03-18 18:57:26 +01:00
parent 8e590df92f
commit fc9a6d6b1e
4 changed files with 15 additions and 17 deletions

View file

@ -1226,11 +1226,11 @@ impl_get_size(const struct spa_handle_factory *factory,
return sizeof(struct impl);
}
static uint32_t channel_from_name(const char *name, size_t len)
static uint32_t channel_from_name(const char *name)
{
int i;
for (i = 0; spa_type_audio_channel[i].name; i++) {
if (strncmp(name, spa_debug_type_short_name(spa_type_audio_channel[i].name), len) == 0)
if (strcmp(name, spa_debug_type_short_name(spa_type_audio_channel[i].name)) == 0)
return spa_type_audio_channel[i].type;
}
return SPA_AUDIO_CHANNEL_UNKNOWN;
@ -1240,16 +1240,15 @@ static inline uint32_t parse_position(uint32_t *pos, const char *val, size_t len
{
struct spa_json it[2];
char v[256];
int l;
uint32_t i = 0;
spa_json_init(&it[0], val, len);
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
spa_json_init(&it[1], val, len);
while ((l = spa_json_get_string(&it[1], v, sizeof(v))) > 0 &&
while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 &&
i < SPA_AUDIO_MAX_CHANNELS) {
pos[i++] = channel_from_name(v, l);
pos[i++] = channel_from_name(v);
}
return i;
}