Fix invalid read in setlocale()

Fix suspicious warnings "Invalid read" of setlocale() detected by valgrind2.
This commit is contained in:
Takashi Iwai 2005-08-18 14:58:31 +00:00
parent e120114bde
commit 1fdd1a6c19

View file

@ -499,16 +499,21 @@ static int safe_strtod(const char *str, double *val)
char *end; char *end;
double v; double v;
char *saved_locale; char *saved_locale;
char locstr[64]; /* enough? */
int err; int err;
if (!*str) if (!*str)
return -EINVAL; return -EINVAL;
saved_locale = setlocale(LC_NUMERIC, NULL); saved_locale = setlocale(LC_NUMERIC, NULL);
setlocale(LC_NUMERIC, "C"); if (saved_locale) {
snprintf(locstr, sizeof(locstr), "%s", saved_locale);
setlocale(LC_NUMERIC, "C");
}
errno = 0; errno = 0;
v = strtod(str, &end); v = strtod(str, &end);
err = -errno; err = -errno;
setlocale(LC_NUMERIC, saved_locale); if (saved_locale)
setlocale(LC_NUMERIC, locstr);
if (err) if (err)
return err; return err;
if (*end) if (*end)
@ -993,7 +998,7 @@ static int parse_array_def(snd_config_t *father, input_t *input, int idx, int sk
snd_config_t *n = NULL; snd_config_t *n = NULL;
if (!skip) { if (!skip) {
char static_id[12]; char static_id[12];
snprintf(static_id, sizeof(static_id), "%i", idx); snprintf(static_id, sizeof(static_id), "%i", idx);
id = strdup(static_id); id = strdup(static_id);
if (id == NULL) if (id == NULL)