summaryrefslogtreecommitdiff
path: root/sys/src/libc
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@gmx.de>2013-08-14 18:49:45 +0200
committercinap_lenrek <cinap_lenrek@gmx.de>2013-08-14 18:49:45 +0200
commitc23a2f6a798cabd3a51274f2fbd214b7286720f3 (patch)
tree024df85d4d5bf6c04f4d0656ec4318a89307c33a /sys/src/libc
parent508b53a29a74d2ded6b15ffc8be0a182b258869a (diff)
libc: Prevent infinite recursion when modf is called with NaN or Inf argument. (apply richard millers / modf-nan patch from sources)
Diffstat (limited to 'sys/src/libc')
-rw-r--r--sys/src/libc/port/frexp.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/sys/src/libc/port/frexp.c b/sys/src/libc/port/frexp.c
index 669f12152..e2f4fb072 100644
--- a/sys/src/libc/port/frexp.c
+++ b/sys/src/libc/port/frexp.c
@@ -89,6 +89,16 @@ modf(double d, double *ip)
FPdbleword x;
int e;
+ x.x = d;
+ e = (x.hi >> SHIFT) & MASK;
+ if(e == MASK){
+ *ip = d;
+ if(x.lo != 0 || (x.hi & 0xfffffL != 0)) /* NaN */
+ return d;
+ /* ±Inf */
+ x.hi &= 0x80000000L;
+ return x.x;
+ }
if(d < 1) {
if(d < 0) {
x.x = modf(-d, ip);
@@ -98,8 +108,7 @@ modf(double d, double *ip)
*ip = 0;
return d;
}
- x.x = d;
- e = ((x.hi >> SHIFT) & MASK) - BIAS;
+ e -= BIAS;
if(e <= SHIFT+1) {
x.hi &= ~(0x1fffffL >> e);
x.lo = 0;