summaryrefslogtreecommitdiffstats
path: root/lib/libc/gdtoa/strtod.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/gdtoa/strtod.c')
-rw-r--r--lib/libc/gdtoa/strtod.c43
1 files changed, 37 insertions, 6 deletions
diff --git a/lib/libc/gdtoa/strtod.c b/lib/libc/gdtoa/strtod.c
index e6a2c699c43..2d2aa375105 100644
--- a/lib/libc/gdtoa/strtod.c
+++ b/lib/libc/gdtoa/strtod.c
@@ -74,7 +74,7 @@ strtod
double aadj, aadj1, adj, rv, rv0;
Long L;
ULong y, z;
- Bigint *bb, *bb1, *bd, *bd0, *bs, *delta;
+ Bigint *bb, *bb1, *bd, *bd0 = NULL, *bs, *delta;
#ifdef SET_INEXACT
int inexact, oldinexact;
#endif
@@ -163,6 +163,8 @@ strtod
sign = 0;
case STRTOG_Zero:
break;
+ case STRTOG_NoMemory:
+ goto ovfl;
default:
if (bb) {
copybits(bits, fpi.nbits, bb);
@@ -331,7 +333,6 @@ strtod
#endif
dval(rv) = tens[k - 9] * dval(rv) + z;
}
- bd0 = 0;
if (nd <= DBL_DIG
#ifndef RND_PRODQUOT
#ifndef Honor_FLT_ROUNDS
@@ -548,12 +549,20 @@ strtod
/* Put digits into bd: true value = bd * 10^e */
bd0 = s2b(s0, nd0, nd, y);
+ if (bd0 == NULL)
+ goto ovfl;
for(;;) {
bd = Balloc(bd0->k);
+ if (bd == NULL)
+ goto ovfl;
Bcopy(bd, bd0);
bb = d2b(dval(rv), &bbe, &bbbits); /* rv = bb * 2^bbe */
+ if (bb == NULL)
+ goto ovfl;
bs = i2b(1);
+ if (bs == NULL)
+ goto ovfl;
if (e >= 0) {
bb2 = bb5 = 0;
@@ -610,19 +619,37 @@ strtod
}
if (bb5 > 0) {
bs = pow5mult(bs, bb5);
+ if (bs == NULL)
+ goto ovfl;
bb1 = mult(bs, bb);
+ if (bb1 == NULL)
+ goto ovfl;
Bfree(bb);
bb = bb1;
}
- if (bb2 > 0)
+ if (bb2 > 0) {
bb = lshift(bb, bb2);
- if (bd5 > 0)
+ if (bb == NULL)
+ goto ovfl;
+ }
+ if (bd5 > 0) {
bd = pow5mult(bd, bd5);
- if (bd2 > 0)
+ if (bd == NULL)
+ goto ovfl;
+ }
+ if (bd2 > 0) {
bd = lshift(bd, bd2);
- if (bs2 > 0)
+ if (bd == NULL)
+ goto ovfl;
+ }
+ if (bs2 > 0) {
bs = lshift(bs, bs2);
+ if (bs == NULL)
+ goto ovfl;
+ }
delta = diff(bb, bd);
+ if (delta == NULL)
+ goto ovfl;
dsign = delta->sign;
delta->sign = 0;
i = cmp(delta, bs);
@@ -655,6 +682,8 @@ strtod
#endif
{
delta = lshift(delta,Log2P);
+ if (delta == NULL)
+ goto ovfl;
if (cmp(delta, bs) <= 0)
adj = -0.5;
}
@@ -747,6 +776,8 @@ strtod
break;
}
delta = lshift(delta,Log2P);
+ if (delta == NULL)
+ goto ovfl;
if (cmp(delta, bs) > 0)
goto drop_down;
break;