diff --git a/lib/libc/gdtoa/dtoa.c b/lib/libc/gdtoa/dtoa.c index 66fe35cdcf2b..538d78e5e469 100644 --- a/lib/libc/gdtoa/dtoa.c +++ b/lib/libc/gdtoa/dtoa.c @@ -1,4 +1,4 @@ -/* $NetBSD: dtoa.c,v 1.10 2012/05/16 17:48:59 alnsn Exp $ */ +/* $NetBSD: dtoa.c,v 1.11 2021/05/06 16:15:33 christos Exp $ */ /**************************************************************** @@ -787,6 +787,8 @@ dtoa } #endif b = lshift(b, 1); + if (b == NULL) + return NULL; j = cmp(b, S); #ifdef ROUND_BIASED if (j >= 0) diff --git a/lib/libc/gdtoa/gdtoa.c b/lib/libc/gdtoa/gdtoa.c index 7982912ac413..a80ddf610cc2 100644 --- a/lib/libc/gdtoa/gdtoa.c +++ b/lib/libc/gdtoa/gdtoa.c @@ -1,4 +1,4 @@ -/* $NetBSD: gdtoa.c,v 1.7 2019/08/01 02:27:43 riastradh Exp $ */ +/* $NetBSD: gdtoa.c,v 1.8 2021/05/06 16:15:33 christos Exp $ */ /**************************************************************** @@ -601,10 +601,16 @@ gdtoa */ i = ((s5 ? hi0bits(S->x[S->wds-1]) : ULbits - 1) - s2 - 4) & kmask; m2 += i; - if ((b2 += i) > 0) + if ((b2 += i) > 0) { b = lshift(b, b2); - if ((s2 += i) > 0) + if (b == NULL) + return NULL; + } + if ((s2 += i) > 0) { S = lshift(S, s2); + if (S == NULL) + return NULL; + } if (k_check) { if (cmp(b,S) < 0) { k--; diff --git a/lib/libc/gdtoa/strtoIg.c b/lib/libc/gdtoa/strtoIg.c index 2ae66bb32a1d..0af36eb81a62 100644 --- a/lib/libc/gdtoa/strtoIg.c +++ b/lib/libc/gdtoa/strtoIg.c @@ -1,4 +1,4 @@ -/* $NetBSD: strtoIg.c,v 1.4 2019/08/01 02:27:43 riastradh Exp $ */ +/* $NetBSD: strtoIg.c,v 1.5 2021/05/06 16:15:33 christos Exp $ */ /**************************************************************** @@ -119,6 +119,8 @@ strtoIg(CONST char *s00, char **se, CONST FPI *fpi, Long *exp, Bigint **B, int * } else { b1 = lshift(b1, 1); + if (b1 == NULL) + return STRTOG_NoMemory; b1->x[0] |= 1; --e1; } diff --git a/lib/libc/gdtoa/strtod.c b/lib/libc/gdtoa/strtod.c index c9bd89f6e00d..e703daef68b1 100644 --- a/lib/libc/gdtoa/strtod.c +++ b/lib/libc/gdtoa/strtod.c @@ -1,4 +1,4 @@ -/* $NetBSD: strtod.c,v 1.17 2020/09/18 14:19:34 christos Exp $ */ +/* $NetBSD: strtod.c,v 1.18 2021/05/06 16:15:33 christos Exp $ */ /**************************************************************** @@ -712,6 +712,8 @@ _int_strtod_l(CONST char *s00, char **se, locale_t loc) #endif { delta = lshift(delta,Log2P); + if (delta == NULL) + goto ovfl; if (cmp(delta, bs) <= 0) dval(&adj) = -0.5; } @@ -804,6 +806,8 @@ _int_strtod_l(CONST char *s00, char **se, locale_t loc) break; } delta = lshift(delta,Log2P); + if (delta == NULL) + goto ovfl; if (cmp(delta, bs) > 0) goto drop_down; break; diff --git a/lib/libc/gdtoa/strtodg.c b/lib/libc/gdtoa/strtodg.c index d0a910594561..d87bf718d3ee 100644 --- a/lib/libc/gdtoa/strtodg.c +++ b/lib/libc/gdtoa/strtodg.c @@ -1,4 +1,4 @@ -/* $NetBSD: strtodg.c,v 1.12 2013/04/19 10:41:53 joerg Exp $ */ +/* $NetBSD: strtodg.c,v 1.13 2021/05/06 16:15:33 christos Exp $ */ /**************************************************************** @@ -248,8 +248,11 @@ rvOK } } } - else if (bdif < 0) + else if (bdif < 0) { b = lshift(b, -bdif); + if (b == NULL) + return STRTOG_NoMemory; + } if (e < fpi->emin) { k = fpi->emin - e; e = fpi->emin; @@ -679,6 +682,8 @@ strtodg(CONST char *s00, char **se, CONST FPI *fpi, Long *expt, ULong *bits, j = rve - emin; if (j > 0) { rvb = lshift(rvb, j); + if (rvb == NULL) + return STRTOG_NoMemory; rvbits += j; } else if (j < 0) { @@ -950,8 +955,11 @@ strtodg(CONST char *s00, char **se, CONST FPI *fpi, Long *expt, ULong *bits, return STRTOG_NoMemory; if (abe < 0) rshift(ab, -abe); - else if (abe > 0) + else if (abe > 0) { ab = lshift(ab, abe); + if (ab == NULL) + return STRTOG_NoMemory; + } rvb0 = rvb; if (asub) { /* rv -= adj; */ @@ -1027,8 +1035,11 @@ strtodg(CONST char *s00, char **se, CONST FPI *fpi, Long *expt, ULong *bits, Bfree(delta); } if (!denorm && (j = nbits - rvbits)) { - if (j > 0) + if (j > 0) { rvb = lshift(rvb, j); + if (rvb == NULL) + return STRTOG_NoMemory; + } else rshift(rvb, -j); rve -= j;