>From a908d89696b20446e276fd6da143262f959fae9a Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 1 Feb 2019 00:18:57 +0100 Subject: [PATCH 1/4] strtod, strtold: Work around HP-UX 11.31/ia64 bug. * lib/strtod.c (STRTOD): When there is an extra character after the exponent marker 'p', reparse the number. * doc/posix-functions/strtod.texi: Document the HP-UX 11.31 bug. * doc/posix-functions/strtold.texi: Likewise. --- ChangeLog | 8 ++++++++ doc/posix-functions/strtod.texi | 5 +++++ doc/posix-functions/strtold.texi | 5 +++++ lib/strtod.c | 20 +++++++++++++++++++- 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 5ab5d83..991db2b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2019-01-31 Bruno Haible + + strtod, strtold: Work around HP-UX 11.31/ia64 bug. + * lib/strtod.c (STRTOD): When there is an extra character after the + exponent marker 'p', reparse the number. + * doc/posix-functions/strtod.texi: Document the HP-UX 11.31 bug. + * doc/posix-functions/strtold.texi: Likewise. + 2019-01-29 Bruno Haible strtold: Add tests. diff --git a/doc/posix-functions/strtod.texi b/doc/posix-functions/strtod.texi index 72ce8bc..ac9ed21 100644 --- a/doc/posix-functions/strtod.texi +++ b/doc/posix-functions/strtod.texi @@ -59,6 +59,11 @@ NetBSD 5.0, OpenBSD 4.0, AIX 5.1, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, Solaris 11.4, mingw, MSVC 14. @item +In hexadecimal floats, this function allows whitespace between @samp{p} +and the exponent on some platforms: +HP-UX 11.31/ia64. + address@hidden This function returns the wrong end pointer for @samp{0x1p} on some platforms: AIX 7.1. diff --git a/doc/posix-functions/strtold.texi b/doc/posix-functions/strtold.texi index f136c54..028915e 100644 --- a/doc/posix-functions/strtold.texi +++ b/doc/posix-functions/strtold.texi @@ -57,6 +57,11 @@ glibc-2.3.2, mingw, Haiku. This function fails to parse C99 hexadecimal floating point on some platforms: IRIX 6.5, mingw. + address@hidden +In hexadecimal floats, this function allows whitespace between @samp{p} +and the exponent on some platforms: +HP-UX 11.31/ia64. @end itemize Portability problems not fixed by Gnulib: diff --git a/lib/strtod.c b/lib/strtod.c index 1d1ba27..2733ff9 100644 --- a/lib/strtod.c +++ b/lib/strtod.c @@ -297,7 +297,25 @@ STRTOD (const char *nptr, char **endptr) while (p < end && c_tolower (*p) != 'p') p++; if (p < end && ! c_isdigit (p[1 + (p[1] == '-' || p[1] == '+')])) - end = p; + { + char *dup = strdup (s); + errno = saved_errno; + if (!dup) + { + /* Not really our day, is it. Rounding errors are + better than outright failure. */ + num = parse_number (s + 2, 16, 2, 4, 'p', &endbuf); + } + else + { + dup[p - s] = '\0'; + num = STRTOD (dup, &endbuf); + saved_errno = errno; + free (dup); + errno = saved_errno; + } + end = p; + } } } else -- 2.7.4