mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-11-01 22:58:49 -04:00
alsa-lib: fix the array parser (unique compound keys)
The code from the old import may merge arrays wrongly and
the result is a compound with same keys like:
Input:
lines [
"SSP0.OUT, , BUF1.3"
]
lines [
"BUF2.0, , SSP0.IN"
]
Parsed contents:
lines {
0 'SSP0.OUT, , BUF1.3'
0 'BUF2.0, , SSP0.IN'
}
Proper parsed contents (create+merge mode):
lines {
0 'SSP0.OUT, , BUF1.3'
1 'BUF2.0, , SSP0.IN'
}
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
parent
1744159180
commit
9980e18c3c
1 changed files with 17 additions and 3 deletions
20
src/conf.c
20
src/conf.c
|
|
@ -1226,7 +1226,7 @@ static int parse_value(snd_config_t **_n, snd_config_t *parent, input_t *input,
|
|||
static int parse_defs(snd_config_t *parent, input_t *input, int skip, int override);
|
||||
static int parse_array_defs(snd_config_t *farther, input_t *input, int skip, int override);
|
||||
|
||||
static int parse_array_def(snd_config_t *parent, input_t *input, int idx, int skip, int override)
|
||||
static int parse_array_def(snd_config_t *parent, input_t *input, int *idx, int skip, int override)
|
||||
{
|
||||
char *id = NULL;
|
||||
int c;
|
||||
|
|
@ -1234,8 +1234,21 @@ static int parse_array_def(snd_config_t *parent, input_t *input, int idx, int sk
|
|||
snd_config_t *n = NULL;
|
||||
|
||||
if (!skip) {
|
||||
snd_config_t *g;
|
||||
char static_id[12];
|
||||
snprintf(static_id, sizeof(static_id), "%i", idx);
|
||||
while (1) {
|
||||
snprintf(static_id, sizeof(static_id), "%i", *idx);
|
||||
if (_snd_config_search(parent, static_id, -1, &g) == 0) {
|
||||
if (override) {
|
||||
snd_config_delete(n);
|
||||
} else {
|
||||
/* merge */
|
||||
(*idx)++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
id = strdup(static_id);
|
||||
if (id == NULL)
|
||||
return -ENOMEM;
|
||||
|
|
@ -1306,9 +1319,10 @@ static int parse_array_defs(snd_config_t *parent, input_t *input, int skip, int
|
|||
unget_char(c, input);
|
||||
if (c == ']')
|
||||
return 0;
|
||||
err = parse_array_def(parent, input, idx++, skip, override);
|
||||
err = parse_array_def(parent, input, &idx, skip, override);
|
||||
if (err < 0)
|
||||
return err;
|
||||
idx++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue