mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-11-04 13:30:08 -05:00
Fix invalid read in setlocale()
Fix suspicious warnings "Invalid read" of setlocale() detected by valgrind2.
This commit is contained in:
parent
e120114bde
commit
1fdd1a6c19
1 changed files with 8 additions and 3 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue