ref: 84e58b7dadb914b745dd49376b9a74fb37bc4727
parent: ea7644951223db92fb058a206d85423b7652998e
author: cinap_lenrek <cinap_lenrek@gmx.de>
date: Wed Aug 14 14:49:45 EDT 2013
libc: Prevent infinite recursion when modf is called with NaN or Inf argument. (apply richard millers / modf-nan patch from sources)
--- a/sys/src/libc/port/frexp.c
+++ b/sys/src/libc/port/frexp.c
@@ -89,6 +89,16 @@
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 @@
*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;
--
⑨