Re: [hackers] [sbase] ed: Use reallocarray || Michael Forney

From: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
Date: Thu, 2 Jan 2020 12:34:06 +0100

On Thu, Jan 02, 2020 at 08:28:40AM +0000, k0ga wrote:
> Hi,
>
>
> On Tue, Dec 31, 2019 at 10:47:28PM +0100, git_AT_suckless.org wrote:
> > diff --git a/ed.c b/ed.c
> > index b844e86..e998e81 100644
> > --- a/ed.c
> > +++ b/ed.c
> > _AT_@ -204,7 +204,7 @@ makeline(char *s, int *off)
> > if (lastidx >= idxsize) {
> > lp = NULL;
> > if (idxsize <= SIZE_MAX - NUMLINES)
> > - lp = realloc(zero, (idxsize + NUMLINES) * sizeof(*lp));
> > + lp = reallocarray(zero, idxsize + NUMLINES, sizeof(*lp));
>
> reallocarray is not a posix function, so it shouldn't be used here. If you
> don't fell confortable using realloc due to the possibility of overflow then
> you should add an explicit check against it.
>
> Regards,
>

sbase has reallocarray in libutil:
https://git.suckless.org/sbase/file/libutil/reallocarray.c.html

-- 
Kind regards,
Hiltjo
Received on Thu Jan 02 2020 - 12:34:06 CET

This archive was generated by hypermail 2.3.0 : Thu Jan 02 2020 - 12:36:25 CET