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.
This commit is contained in:
parent
2ca7a12a81
commit
10a381e55a
@ -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 {
|
||||
|
@ -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;
|
||||
|
@ -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:
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user