Skip to content

Commit 77edd59

Browse files
committed
Merge branch 'sk/calloc-not-malloc-plus-memset'
Code clean-up. * sk/calloc-not-malloc-plus-memset: git: use calloc instead of malloc + memset where possible
2 parents 88e59f8 + 7525cd8 commit 77edd59

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
@@ -2873,9 +2873,9 @@ void apply_push_cas(struct push_cas_option *cas,
28732873

28742874
struct remote_state *remote_state_new(void)
28752875
{
2876-
struct remote_state *r = xmalloc(sizeof(*r));
2876+
struct remote_state *r;
28772877

2878-
memset(r, 0, sizeof(*r));
2878+
CALLOC_ARRAY(r, 1);
28792879

28802880
hashmap_init(&r->remotes_hash, remotes_hash_cmp, NULL, 0);
28812881
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
@@ -1490,14 +1490,13 @@ struct fetch_task {
14901490
*/
14911491
static const struct submodule *get_non_gitmodules_submodule(const char *path)
14921492
{
1493-
struct submodule *ret = NULL;
1493+
struct submodule *ret;
14941494
const char *name = default_name_or_path(path);
14951495

14961496
if (!name)
14971497
return NULL;
14981498

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

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

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

0 commit comments

Comments
 (0)