> Date: Fri, 25 Dec 2015 14:17:19 +0100 > From: Theo Buehler <t...@math.ethz.ch> > > On Thu, Dec 24, 2015 at 12:41:28PM -0500, Michael McConville wrote: > > 1. realloc acts like malloc when ptr == NULL > > Why not > > "#endif", > - " if (newsize && YY_SIZE_MAX / newsize < sizeof *newss)", > - " goto bail;", > - " newss = yyss ? (short *)realloc(yyss, newsize * sizeof *newss) :", > - " (short *)malloc(newsize * sizeof *newss); /* overflow check > above */", > + " newss = reallocarray(yyss, newsize, sizeof(*newss)); > > instead? > > Note however that the commit message in which the overflow checks were > introduced says > > revision 1.28 > date: 2007/09/03 21:14:58; author: deraadt; state: Exp; lines: +13 -4; > move back to using malloc() instead of calloc(), because the yacc > skeleton really should only call malloc/realloc/free, no other external > APIs at all. theefore, add a pre-check for the overflow case, thus > protecting realloc too; tested mblamer, ok millert, help from kettenis > > but that was long before reallocarray existed, so I'm not sure.
IMNSHO the code produced by OpenBSD's yacc should be portable; reallocarray isn't portable.