diff options
author | Thomas Schwinge <thomas@codesourcery.com> | 2013-05-23 18:00:10 +0200 |
---|---|---|
committer | Thomas Schwinge <thomas@codesourcery.com> | 2013-08-29 12:22:10 +0200 |
commit | 0007fc9bdd1d9efcd52d07837f2cd085b5a8f58b (patch) | |
tree | b3c86dbee5b95c24a8413be634ae11318ceb2f8e /stdlib | |
parent | f1cc4c8654b6bc431273286d3562942c50975caf (diff) | |
download | glibc-0007fc9bdd1d9efcd52d07837f2cd085b5a8f58b.tar.gz |
[BZ #15522] strtod ("nan(N)") returning a sNaN in some cases
Diffstat (limited to 'stdlib')
-rw-r--r-- | stdlib/strtod_l.c | 9 | ||||
-rw-r--r-- | stdlib/strtof_l.c | 7 | ||||
-rw-r--r-- | stdlib/tst-strtod6.c | 24 |
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" |