[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: sleep with LANG="address@hidden"
From: |
Paul Eggert |
Subject: |
Re: sleep with LANG="address@hidden" |
Date: |
29 Nov 2003 00:50:42 -0800 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 |
Jim Meyering <address@hidden> writes:
> Wouldn't it be better (in case xstrtod is called with a
> modified LC_NUMERIC locale) if c_strtod restored the original
> setting for LC_NUMERIC, rather than the environment-derived one?
I was lazy and assumed that c_strtod would be called
only in environments where LC_NUMERIC was set from the
environment.
> --- lib/c-strtod.c 27 Nov 2003 07:46:01 -0000 1.1
> +++ lib/c-strtod.c 27 Nov 2003 08:31:30 -0000
> @@ -27,8 +27,9 @@ double
> c_strtod (char const *nptr, char **endptr)
> {
> double r;
> + char const *saved_locale = setlocale (LC_NUMERIC, NULL);
> setlocale (LC_NUMERIC, "C");
This isn't right, since the second setlocale can overwrite the storage
addressed by saved_locale.
> r = strtod (nptr, endptr);
> - setlocale (LC_NUMERIC, "");
> + setlocale (LC_NUMERIC, saved_locale);
saved_locale might be null.
Maybe this instead?
double r;
char *saved_locale = setlocale (LC_NUMERIC, NULL);
if (saved_locale)
{
saved_locale = xstrdup (saved_locale);
setlocale (LC_NUMERIC, "C");
}
r = strtod (nptr, endptr);
if (saved_locale)
{
setlocale (LC_NUMERIC, saved_locale);
free (saved_locale);
}
return r;