diff lib/strtod.c @ 40169:ecb43221748b

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.
author Bruno Haible <bruno@clisp.org>
date Fri, 01 Feb 2019 00:18:57 +0100
parents cdb3438ceb13
children 201ca4418b4b
line wrap: on
line diff
--- a/lib/strtod.c	Thu Jan 31 13:24:44 2019 -0800
+++ b/lib/strtod.c	Fri Feb 01 00:18:57 2019 +0100
@@ -297,7 +297,25 @@
               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