summary refs log tree commit diff
path: root/stdlib
diff options
context:
space:
mode:
authorThomas Schwinge <thomas@codesourcery.com>2013-05-23 18:00:10 +0200
committerThomas Schwinge <thomas@codesourcery.com>2013-08-29 12:22:10 +0200
commit0007fc9bdd1d9efcd52d07837f2cd085b5a8f58b (patch)
treeb3c86dbee5b95c24a8413be634ae11318ceb2f8e /stdlib
parentf1cc4c8654b6bc431273286d3562942c50975caf (diff)
downloadglibc-0007fc9bdd1d9efcd52d07837f2cd085b5a8f58b.tar.gz
glibc-0007fc9bdd1d9efcd52d07837f2cd085b5a8f58b.tar.xz
glibc-0007fc9bdd1d9efcd52d07837f2cd085b5a8f58b.zip
[BZ #15522] strtod ("nan(N)") returning a sNaN in some cases
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/strtod_l.c9
-rw-r--r--stdlib/strtof_l.c7
-rw-r--r--stdlib/tst-strtod6.c24
3 files changed, 29 insertions, 11 deletions
diff --git a/stdlib/strtod_l.c b/stdlib/strtod_l.c
index 5b41e2b06e..8f60653fb0 100644
--- a/stdlib/strtod_l.c
+++ b/stdlib/strtod_l.c
@@ -42,11 +42,10 @@ extern unsigned long long int ____strtoull_l_internal (const char *, char **,
 # define SET_MANTISSA(flt, mant) \
   do { union ieee754_double u;						      \
        u.d = (flt);							      \
-       if ((mant & 0xfffffffffffffULL) == 0)				      \
-	 mant = 0x8000000000000ULL;					      \
-       u.ieee.mantissa0 = ((mant) >> 32) & 0xfffff;			      \
-       u.ieee.mantissa1 = (mant) & 0xffffffff;				      \
-       (flt) = u.d;							      \
+       u.ieee_nan.mantissa0 = (mant) >> 32;				      \
+       u.ieee_nan.mantissa1 = (mant);					      \
+       if ((u.ieee.mantissa0 | u.ieee.mantissa1) != 0)			      \
+	 (flt) = u.d;							      \
   } while (0)
 #endif
 /* End of configuration part.  */
diff --git a/stdlib/strtof_l.c b/stdlib/strtof_l.c
index 6fb44bd403..c4c1c1f2dd 100644
--- a/stdlib/strtof_l.c
+++ b/stdlib/strtof_l.c
@@ -37,10 +37,9 @@ extern unsigned long long int ____strtoull_l_internal (const char *, char **,
 #define SET_MANTISSA(flt, mant) \
   do { union ieee754_float u;						      \
        u.f = (flt);							      \
-       if ((mant & 0x7fffff) == 0)					      \
-	 mant = 0x400000;						      \
-       u.ieee.mantissa = (mant) & 0x7fffff;				      \
-       (flt) = u.f;							      \
+       u.ieee_nan.mantissa = (mant);					      \
+       if (u.ieee.mantissa != 0)					      \
+	 (flt) = u.f;							      \
   } while (0)
 
 #include "strtod_l.c"
diff --git a/stdlib/tst-strtod6.c b/stdlib/tst-strtod6.c
index 1d87266a27..15e79fddfb 100644
--- a/stdlib/tst-strtod6.c
+++ b/stdlib/tst-strtod6.c
@@ -4,12 +4,13 @@
 #include <string.h>
 
 static int
-do_test (void)
+test (const char str[])
 {
-  static const char str[] = "NaN(blabla)something";
   char *endp;
   int result = 0;
 
+  puts (str);
+
   double d = strtod (str, &endp);
   if (!isnan (d))
     {
@@ -64,5 +65,24 @@ do_test (void)
   return result;
 }
 
+static int
+do_test (void)
+{
+  int result = 0;
+
+  result |= test ("NaN(blabla)something");
+  result |= test ("NaN(1234)something");
+  /* UINT32_MAX.  */
+  result |= test ("NaN(4294967295)something");
+  /* UINT64_MAX.  */
+  result |= test ("NaN(18446744073709551615)something");
+  /* The case of zero is special in that "something" has to be done to make the
+     mantissa different from zero, which would mean infinity instead of
+     NaN.  */
+  result |= test ("NaN(0)something");
+
+  return result;
+}
+
 #define TEST_FUNCTION do_test ()
 #include "../test-skeleton.c"