On Fri, Feb 19, 2021 at 10:27:06AM +0100, Theo Buehler wrote:
> As discussed a few days ago, there are a few reallocarray + memset that
> can be directly handled by recallocarray.

Fine with me.
 
> Index: main.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/rpki-client/main.c,v
> retrieving revision 1.101
> diff -u -p -r1.101 main.c
> --- main.c    18 Feb 2021 10:10:20 -0000      1.101
> +++ main.c    19 Feb 2021 08:56:19 -0000
> @@ -265,12 +265,12 @@ repo_alloc(void)
>  {
>       struct repo *rp;
>  
> -     rt.repos = reallocarray(rt.repos, rt.reposz + 1, sizeof(struct repo));
> +     rt.repos = recallocarray(rt.repos, rt.reposz, rt.reposz + 1,
> +         sizeof(struct repo));
>       if (rt.repos == NULL)
> -             err(1, "reallocarray");
> +             err(1, "recallocarray");
>  
>       rp = &rt.repos[rt.reposz++];
> -     memset(rp, 0, sizeof(struct repo));
>       rp->id = rt.reposz - 1;
>  
>       return rp;
> Index: mft.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/rpki-client/mft.c,v
> retrieving revision 1.26
> diff -u -p -r1.26 mft.c
> --- mft.c     16 Feb 2021 07:58:30 -0000      1.26
> +++ mft.c     19 Feb 2021 07:04:25 -0000
> @@ -193,13 +193,12 @@ mft_parse_filehash(struct parse *p, cons
>  
>       /* Insert the filename and hash value. */
>  
> -     p->res->files = reallocarray(p->res->files, p->res->filesz + 1,
> -         sizeof(struct mftfile));
> +     p->res->files = recallocarray(p->res->files, p->res->filesz,
> +         p->res->filesz + 1, sizeof(struct mftfile));
>       if (p->res->files == NULL)
>               err(1, NULL);
>  
>       fent = &p->res->files[p->res->filesz++];
> -     memset(fent, 0, sizeof(struct mftfile));
>  
>       fent->file = fn;
>       fn = NULL;
> Index: roa.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/rpki-client/roa.c,v
> retrieving revision 1.14
> diff -u -p -r1.14 roa.c
> --- roa.c     16 Feb 2021 07:58:30 -0000      1.14
> +++ roa.c     19 Feb 2021 07:07:30 -0000
> @@ -111,12 +111,11 @@ roa_parse_addr(const ASN1_OCTET_STRING *
>               /* FIXME: maximum check. */
>       }
>  
> -     p->res->ips = reallocarray(p->res->ips,
> -             p->res->ipsz + 1, sizeof(struct roa_ip));
> +     p->res->ips = recallocarray(p->res->ips, p->res->ipsz, p->res->ipsz + 1,
> +         sizeof(struct roa_ip));
>       if (p->res->ips == NULL)
>               err(1, NULL);
>       res = &p->res->ips[p->res->ipsz++];
> -     memset(res, 0, sizeof(struct roa_ip));
>  
>       res->addr = addr;
>       res->afi = afi;
> 

-- 
:wq Claudio

Reply via email to