mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2026-02-25 01:40:10 -05:00
ucm: parser - use less memory for integer/real values in parse_value()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
parent
d8dfe4dac7
commit
27f97ab585
1 changed files with 10 additions and 13 deletions
|
|
@ -567,6 +567,7 @@ static int parse_value(snd_use_case_mgr_t *uc_mgr ATTRIBUTE_UNUSED,
|
||||||
struct ucm_value *curr;
|
struct ucm_value *curr;
|
||||||
snd_config_iterator_t i, next;
|
snd_config_iterator_t i, next;
|
||||||
snd_config_t *n;
|
snd_config_t *n;
|
||||||
|
char buf[64];
|
||||||
long l;
|
long l;
|
||||||
long long ll;
|
long long ll;
|
||||||
double d;
|
double d;
|
||||||
|
|
@ -595,26 +596,22 @@ static int parse_value(snd_use_case_mgr_t *uc_mgr ATTRIBUTE_UNUSED,
|
||||||
type = snd_config_get_type(n);
|
type = snd_config_get_type(n);
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case SND_CONFIG_TYPE_INTEGER:
|
case SND_CONFIG_TYPE_INTEGER:
|
||||||
curr->data = malloc(16);
|
snd_config_get_integer(n, &l);
|
||||||
|
snprintf(buf, sizeof(buf), "%li", l);
|
||||||
|
__buf:
|
||||||
|
curr->data = malloc(strlen(buf) + 1);
|
||||||
if (curr->data == NULL)
|
if (curr->data == NULL)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
snd_config_get_integer(n, &l);
|
strcpy(curr->data, buf);
|
||||||
sprintf(curr->data, "%li", l);
|
|
||||||
break;
|
break;
|
||||||
case SND_CONFIG_TYPE_INTEGER64:
|
case SND_CONFIG_TYPE_INTEGER64:
|
||||||
curr->data = malloc(32);
|
|
||||||
if (curr->data == NULL)
|
|
||||||
return -ENOMEM;
|
|
||||||
snd_config_get_integer64(n, &ll);
|
snd_config_get_integer64(n, &ll);
|
||||||
sprintf(curr->data, "%lli", ll);
|
snprintf(buf, sizeof(buf), "%lli", ll);
|
||||||
break;
|
goto __buf;
|
||||||
case SND_CONFIG_TYPE_REAL:
|
case SND_CONFIG_TYPE_REAL:
|
||||||
curr->data = malloc(64);
|
|
||||||
if (curr->data == NULL)
|
|
||||||
return -ENOMEM;
|
|
||||||
snd_config_get_real(n, &d);
|
snd_config_get_real(n, &d);
|
||||||
sprintf(curr->data, "%-16g", d);
|
snprintf(buf, sizeof(buf), "%-16g", d);
|
||||||
break;
|
goto __buf;
|
||||||
case SND_CONFIG_TYPE_STRING:
|
case SND_CONFIG_TYPE_STRING:
|
||||||
err = parse_string(n, &curr->data);
|
err = parse_string(n, &curr->data);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue