Re: [PATCH 1/2] code cleanup in sha1_file.c: xmalloc -> xcalloc
- From
Brandon Casey <casey@nrlssc.navy.mil>
- Date
- Feb 10, 2009, 16:29 UTC
- Message-ID
- <EohcOnsg9EGsisIaM0B0iYUSHt-mz_fzqBCqg27mBU0yXXlkP9baOA@cipher.nrlssc.navy.mil>
- In-Reply-To
- <1234334612-24907-1-git-send-email-guanqun.lu@gmail.com>
Guanqun Lu wrote:
Show 23 quoted lines
> '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.
>
> Signed-off-by: Guanqun Lu <guanqun.lu@gmail.com>
> ---
> 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;
> }I previously scanned through and did this. I left this one as is because the extra part is about as large as the sizeof(*p) part. 69 and 72 bytes respectively on 32-bit. The extra part is always filled in immediately by callers. It's only called once for each pack so it's not performance critical, so maybe your patch is worth it since it is simpler?
-brandon