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)