PR/56148: Andreas Gustafsson: lib/libc/stdio/t_printf:snprintf_float test

randomly fails.
Add checks to all places where lshift is called because it can return NULL
This commit is contained in:
christos 2021-05-06 16:15:33 +00:00
parent 735b9693ea
commit 9feb722ead
5 changed files with 35 additions and 10 deletions

View File

@ -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)

View File

@ -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--;

View File

@ -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;
}

View File

@ -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;

View File

@ -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;