diff options
author | das <das@FreeBSD.org> | 2007-12-16 21:14:33 +0000 |
---|---|---|
committer | das <das@FreeBSD.org> | 2007-12-16 21:14:33 +0000 |
commit | 70cdf6a57447192c3b77090ed112c732882f95f3 (patch) | |
tree | 5f9e7a4fd4b4e74b456608617e283e71285fad2f /contrib/gdtoa | |
parent | b2367c2d0b77fb617f31b9fafae0c52dc8ecf89e (diff) | |
download | FreeBSD-src-70cdf6a57447192c3b77090ed112c732882f95f3.zip FreeBSD-src-70cdf6a57447192c3b77090ed112c732882f95f3.tar.gz |
Fix strto{f,d,ld}() so they don't return signaling NaNs. C99
says they are never supposed to, and the fact that they did could
cause apps that run with unmasked FP exceptions to SIGFPE after a
scanf() or strtod(). The vendor stated that he will not be fixing
this, citing portability concerns.
Diffstat (limited to 'contrib/gdtoa')
-rw-r--r-- | contrib/gdtoa/strtod.c | 4 | ||||
-rw-r--r-- | contrib/gdtoa/strtof.c | 8 | ||||
-rw-r--r-- | contrib/gdtoa/strtorQ.c | 5 | ||||
-rw-r--r-- | contrib/gdtoa/strtorx.c | 4 |
4 files changed, 17 insertions, 4 deletions
diff --git a/contrib/gdtoa/strtod.c b/contrib/gdtoa/strtod.c index 66a3baa..3703f94 100644 --- a/contrib/gdtoa/strtod.c +++ b/contrib/gdtoa/strtod.c @@ -29,6 +29,8 @@ THIS SOFTWARE. /* Please send bug reports to David M. Gay (dmg at acm dot org, * with " at " changed at "@" and " dot " changed to "."). */ +/* $FreeBSD$ */ + #include "gdtoaimp.h" #ifndef NO_FENV_H #include <fenv.h> @@ -258,7 +260,7 @@ strtod if (*s == '(' /*)*/ && hexnan(&s, &fpinan, bits) == STRTOG_NaNbits) { - word0(rv) = 0x7ff00000 | bits[1]; + word0(rv) = 0x7ff80000 | bits[1]; word1(rv) = bits[0]; } else { diff --git a/contrib/gdtoa/strtof.c b/contrib/gdtoa/strtof.c index 21bc6c1..58486f2 100644 --- a/contrib/gdtoa/strtof.c +++ b/contrib/gdtoa/strtof.c @@ -29,6 +29,8 @@ THIS SOFTWARE. /* Please send bug reports to David M. Gay (dmg at acm dot org, * with " at " changed at "@" and " dot " changed to "."). */ +/* $FreeBSD$ */ + #include "gdtoaimp.h" float @@ -52,10 +54,14 @@ strtof(CONST char *s, char **sp) break; case STRTOG_Normal: - case STRTOG_NaNbits: u.L[0] = bits[0] & 0x7fffff | exp + 0x7f + 23 << 23; break; + case STRTOG_NaNbits: + /* FreeBSD local: always return a quiet NaN */ + u.L[0] = bits[0] | 0x7fc00000; + break; + case STRTOG_Denormal: u.L[0] = bits[0]; break; diff --git a/contrib/gdtoa/strtorQ.c b/contrib/gdtoa/strtorQ.c index a9a07da..b7f9bba 100644 --- a/contrib/gdtoa/strtorQ.c +++ b/contrib/gdtoa/strtorQ.c @@ -29,6 +29,8 @@ THIS SOFTWARE. /* Please send bug reports to David M. Gay (dmg at acm dot org, * with " at " changed at "@" and " dot " changed to "."). */ +/* $FreeBSD$ */ + #include "gdtoaimp.h" #undef _0 @@ -67,7 +69,8 @@ ULtoQ(ULong *L, ULong *bits, Long exp, int k) L[_3] = bits[0]; L[_2] = bits[1]; L[_1] = bits[2]; - L[_0] = (bits[3] & ~0x10000) | ((exp + 0x3fff + 112) << 16); + L[_0] = (bits[3] & ~0x10000) + | (((exp + 0x3fff + 112) << 16) | (1 << 15)); break; case STRTOG_Denormal: diff --git a/contrib/gdtoa/strtorx.c b/contrib/gdtoa/strtorx.c index 23f721a..52d7eff 100644 --- a/contrib/gdtoa/strtorx.c +++ b/contrib/gdtoa/strtorx.c @@ -29,6 +29,8 @@ THIS SOFTWARE. /* Please send bug reports to David M. Gay (dmg at acm dot org, * with " at " changed at "@" and " dot " changed to "."). */ +/* $FreeBSD$ */ + #include "gdtoaimp.h" #undef _0 @@ -75,7 +77,7 @@ ULtox(UShort *L, ULong *bits, Long exp, int k) L[_4] = (UShort)bits[0]; L[_3] = (UShort)(bits[0] >> 16); L[_2] = (UShort)bits[1]; - L[_1] = (UShort)(bits[1] >> 16); + L[_1] = (UShort)((bits[1] >> 16) | (3 << 14)); break; case STRTOG_Infinite: |