Skip to content

Commit 7525cd8

Browse files
Seija Kijingitster
authored andcommitted
git: use calloc instead of malloc + memset where possible
Avoid calling malloc + memset by calling calloc. Signed-off-by: Seija Kijin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d882f38 commit 7525cd8

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

remote.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2854,9 +2854,9 @@ void apply_push_cas(struct push_cas_option *cas,
28542854

28552855
struct remote_state *remote_state_new(void)
28562856
{
2857-
struct remote_state *r = xmalloc(sizeof(*r));
2857+
struct remote_state *r;
28582858

2859-
memset(r, 0, sizeof(*r));
2859+
CALLOC_ARRAY(r, 1);
28602860

28612861
hashmap_init(&r->remotes_hash, remotes_hash_cmp, NULL, 0);
28622862
hashmap_init(&r->branches_hash, branches_hash_cmp, NULL, 0);

submodule.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,14 +1489,13 @@ struct fetch_task {
14891489
*/
14901490
static const struct submodule *get_non_gitmodules_submodule(const char *path)
14911491
{
1492-
struct submodule *ret = NULL;
1492+
struct submodule *ret;
14931493
const char *name = default_name_or_path(path);
14941494

14951495
if (!name)
14961496
return NULL;
14971497

1498-
ret = xmalloc(sizeof(*ret));
1499-
memset(ret, 0, sizeof(*ret));
1498+
CALLOC_ARRAY(ret, 1);
15001499
ret->path = name;
15011500
ret->name = name;
15021501

@@ -1536,8 +1535,9 @@ static struct fetch_task *fetch_task_create(struct submodule_parallel_fetch *spf
15361535
const char *path,
15371536
const struct object_id *treeish_name)
15381537
{
1539-
struct fetch_task *task = xmalloc(sizeof(*task));
1540-
memset(task, 0, sizeof(*task));
1538+
struct fetch_task *task;
1539+
1540+
CALLOC_ARRAY(task, 1);
15411541

15421542
if (validate_submodule_path(path) < 0)
15431543
exit(128);

0 commit comments

Comments
 (0)