Subject: Re: [PATCH 1/2] code cleanup in sha1_file.c: xmalloc -> xcalloc

From: Junio C Hamano <[email-masked]>
Date: Tue, 10 Feb 2009 08:43:46 -0800

Guanqun Lu <[email-masked]> writes:

> 'xmalloc' followed immediately by 'memset' is replaced
> with 'xcalloc', and a simple grep in this project seems
> to show that it's the only place.

But isn't this memset() done only for the initial part of the allocated
area, not the whole thing?  You are not cleaning up but changing what it
does, if I am reading this code correctly.

> Signed-off-by: Guanqun Lu <[email-masked]>
> ---
>  sha1_file.c |    3 +--
>  1 files changed, 1 insertions(+), 2 deletions(-)
>
> diff --git a/sha1_file.c b/sha1_file.c
> index 8868b80..93e5fc0 100644
> --- a/sha1_file.c
> +++ b/sha1_file.c
> @@ -858,8 +858,7 @@ unsigned char* use_pack(struct packed_git *p,
>  
>  static struct packed_git *alloc_packed_git(int extra)
>  {
> -	struct packed_git *p = xmalloc(sizeof(*p) + extra);
> -	memset(p, 0, sizeof(*p));
> +	struct packed_git *p = xcalloc(1, sizeof(*p) + extra);
>  	p->pack_fd = -1;
>  	return p;
>  }
> -- 
> 1.6.1.2.392.gb04d1