use xcalloc() to allocate zero-initialized memory

Use xcalloc() instead of xmalloc() followed by memset() to allocate and zero out memory because it's shorter and avoids duplicating the function parameters. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Jul 19, 2014 at 15:56 UTC 51a60f5bfbaf1ee7c7a2d2b73eca4f042f7af8cb
4 files changed +4 -8
builtin/clean.c
+1 -2
@@ -621,8 +621,7 @@ static int *list_and_choose(struct menu_opts *opts, struct menu_stuff *stuff)
621 nr += chosen[i];
622 }
623
624 - result = xmalloc(sizeof(int) * (nr + 1));
625 - memset(result, 0, sizeof(int) * (nr + 1));
624 + result = xcalloc(nr + 1, sizeof(int));
625 for (i = 0; i < stuff->nr && j < nr; i++) {
626 if (chosen[i])
627 result[j++] = i;
builtin/index-pack.c
+1 -2
@@ -362,8 +362,7 @@ static void set_thread_data(struct thread_local *data)
362
363 static struct base_data *alloc_base_data(void)
364 {
365 - struct base_data *base = xmalloc(sizeof(struct base_data));
366 - memset(base, 0, sizeof(*base));
365 + struct base_data *base = xcalloc(1, sizeof(struct base_data));
366 base->ref_last = -1;
367 base->ofs_last = -1;
368 return base;
compat/mingw.c
+1 -2
@@ -1226,8 +1226,7 @@ static int WSAAPI getaddrinfo_stub(const char *node, const char *service,
1226 else
1227 ai->ai_canonname = NULL;
1228
1229 - sin = xmalloc(ai->ai_addrlen);
1230 - memset(sin, 0, ai->ai_addrlen);
1229 + sin = xcalloc(1, ai->ai_addrlen);
1230 sin->sin_family = AF_INET;
1231 /* Note: getaddrinfo is supposed to allow service to be a string,
1232 * which should be looked up using getservbyname. This is
pathspec.c
+1 -2
@@ -389,8 +389,7 @@ void parse_pathspec(struct pathspec *pathspec,
389 if (!(flags & PATHSPEC_PREFER_CWD))
390 die("BUG: PATHSPEC_PREFER_CWD requires arguments");
391
392 - pathspec->items = item = xmalloc(sizeof(*item));
393 - memset(item, 0, sizeof(*item));
392 + pathspec->items = item = xcalloc(1, sizeof(*item));
393 item->match = prefix;
394 item->original = prefix;
395 item->nowildcard_len = item->len = strlen(prefix);