Skip to content

Commit e91cea8

Browse files
Seija KijinAZero13
authored andcommitted
revision: use calloc instead of malloc where possible
We can avoid having to call memset by calling calloc Signed-off-by: Seija <[email protected]>
1 parent 2ccc89b commit e91cea8

File tree

3 files changed

+12
-19
lines changed

3 files changed

+12
-19
lines changed

builtin/pack-redundant.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,6 @@ static inline struct llist_item *llist_item_get(void)
6363
return new_item;
6464
}
6565

66-
static inline void llist_init(struct llist **list)
67-
{
68-
*list = xmalloc(sizeof(struct llist));
69-
(*list)->front = (*list)->back = NULL;
70-
(*list)->size = 0;
71-
}
72-
7366
static void llist_free(struct llist *list)
7467
{
7568
for (struct llist_item *i = list->front, *next; i; i = next) {
@@ -84,7 +77,7 @@ static struct llist * llist_copy(struct llist *list)
8477
struct llist *ret;
8578
struct llist_item *new_item, *old_item, *prev;
8679

87-
llist_init(&ret);
80+
CALLOC_ARRAY(ret, 1);
8881

8982
if ((ret->size = list->size) == 0)
9083
return ret;
@@ -480,7 +473,7 @@ static void load_all_objects(void)
480473
struct pack_list *pl = local_packs;
481474
struct llist_item *hint, *l;
482475

483-
llist_init(&all_objects);
476+
CALLOC_ARRAY(all_objects, 1);
484477

485478
while (pl) {
486479
hint = NULL;
@@ -507,7 +500,7 @@ static void cmp_local_packs(void)
507500

508501
/* only one packfile */
509502
if (!pl->next) {
510-
llist_init(&pl->unique_objects);
503+
CALLOC_ARRAY(pl->unique_objects, 1);
511504
return;
512505
}
513506

@@ -544,7 +537,7 @@ static struct pack_list * add_pack(struct packed_git *p)
544537
return NULL;
545538

546539
l.pack = p;
547-
llist_init(&l.remaining_objects);
540+
CALLOC_ARRAY(l.remaining_objects, 1);
548541

549542
if (open_pack_index(p))
550543
return NULL;
@@ -650,7 +643,7 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED, s
650643
scan_alt_odb_packs();
651644

652645
/* ignore objects given on stdin */
653-
llist_init(&ignore);
646+
CALLOC_ARRAY(ignore, 1);
654647
if (!isatty(0)) {
655648
struct object_id oid;
656649
while (fgets(buf, sizeof(buf), stdin)) {

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)