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

From: k0ga <k0ga_AT_shike2.com>
Date: Thu, 2 Jan 2020 08:28:40 +0000

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,
Received on Thu Jan 02 2020 - 09:28:40 CET

This archive was generated by hypermail 2.3.0 : Thu Jan 02 2020 - 09:36:24 CET