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;
double v;
char *saved_locale;
char locstr[64]; /* enough? */
int err;
if (!*str)
return -EINVAL;
saved_locale = setlocale(LC_NUMERIC, NULL);
if (saved_locale) {
snprintf(locstr, sizeof(locstr), "%s", saved_locale);
setlocale(LC_NUMERIC, "C");
}
errno = 0;
v = strtod(str, &end);
err = -errno;
setlocale(LC_NUMERIC, saved_locale);
if (saved_locale)
setlocale(LC_NUMERIC, locstr);
if (err)
return err;
if (*end)