Re: git: 419822b372f5 - main - libgeom(3): Use calloc instead of malloc and bzero.

From: Mateusz Piotrowski <0mp_at_FreeBSD.org>
Date: Fri, 11 Mar 2022 10:57:45 UTC
Hi,

I grepped out tree and there are many other places, which could be converted to using calloc. Is 
there anything to watch out for when converting malloc and memset call pairs to calloc?

Best,
Mateusz

On 11/03/2022 10:42, Hans Petter Selasky wrote:
> The branch main has been updated by hselasky:
>
> URL: https://cgit.FreeBSD.org/src/commit/?id=419822b372f543b22d7fb04eae0dffacf058feb6
>
> commit 419822b372f543b22d7fb04eae0dffacf058feb6
> Author:     Hans Petter Selasky <hselasky@FreeBSD.org>
> AuthorDate: 2022-03-10 09:16:27 +0000
> Commit:     Hans Petter Selasky <hselasky@FreeBSD.org>
> CommitDate: 2022-03-11 09:38:16 +0000
>
>      libgeom(3): Use calloc instead of malloc and bzero.
>      
>      Pull Request:   https://github.com/freebsd/freebsd-src/pull/546
>      MFC after:      1 week
>      Sponsored by:   NVIDIA Networking
> ---
>   lib/geom/virstor/geom_virstor.c | 3 +--
>   1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/lib/geom/virstor/geom_virstor.c b/lib/geom/virstor/geom_virstor.c
> index 25ebdebbe7eb..bd8da7337a55 100644
> --- a/lib/geom/virstor/geom_virstor.c
> +++ b/lib/geom/virstor/geom_virstor.c
> @@ -406,10 +406,9 @@ virstor_label(struct gctl_req *req)
>   			} else
>   				strlcpy(md.provider, name, sizeof(md.provider));
>   		}
> -		sect = malloc(ssize);
> +		sect = calloc(ssize, sizeof(unsigned char));
>   		if (sect == NULL)
>   			err(1, "Cannot allocate sector of %zu bytes", ssize);
> -		bzero(sect, ssize);
>   		virstor_metadata_encode(&md, sect);
>   		error = g_metadata_store(name, sect, ssize);
>   		free(sect);
>