Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 51a60f5

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ebc5da3 commit 51a60f5

File tree

4 files changed

+4
-8
lines changed

4 files changed

+4
-8
lines changed

builtin/clean.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,8 +621,7 @@ static int *list_and_choose(struct menu_opts *opts, struct menu_stuff *stuff)
621621
nr += chosen[i];
622622
}
623623

624-
result = xmalloc(sizeof(int) * (nr + 1));
625-
memset(result, 0, sizeof(int) * (nr + 1));
624+
result = xcalloc(nr + 1, sizeof(int));
626625
for (i = 0; i < stuff->nr && j < nr; i++) {
627626
if (chosen[i])
628627
result[j++] = i;

builtin/index-pack.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,7 @@ static void set_thread_data(struct thread_local *data)
362362

363363
static struct base_data *alloc_base_data(void)
364364
{
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));
367366
base->ref_last = -1;
368367
base->ofs_last = -1;
369368
return base;

compat/mingw.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,8 +1226,7 @@ static int WSAAPI getaddrinfo_stub(const char *node, const char *service,
12261226
else
12271227
ai->ai_canonname = NULL;
12281228

1229-
sin = xmalloc(ai->ai_addrlen);
1230-
memset(sin, 0, ai->ai_addrlen);
1229+
sin = xcalloc(1, ai->ai_addrlen);
12311230
sin->sin_family = AF_INET;
12321231
/* Note: getaddrinfo is supposed to allow service to be a string,
12331232
* which should be looked up using getservbyname. This is

pathspec.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,7 @@ void parse_pathspec(struct pathspec *pathspec,
389389
if (!(flags & PATHSPEC_PREFER_CWD))
390390
die("BUG: PATHSPEC_PREFER_CWD requires arguments");
391391

392-
pathspec->items = item = xmalloc(sizeof(*item));
393-
memset(item, 0, sizeof(*item));
392+
pathspec->items = item = xcalloc(1, sizeof(*item));
394393
item->match = prefix;
395394
item->original = prefix;
396395
item->nowildcard_len = item->len = strlen(prefix);

0 commit comments

Comments
 (0)