Jim Meyering <[EMAIL PROTECTED]> 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;
_______________________________________________
Bug-coreutils mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/bug-coreutils