Skip to content

Commit 35f220b

Browse files
SiddharthShrimaligitster
authored andcommitted
submodule--helper: replace malloc with xmalloc
The submodule_summary_callback() function currently uses a raw malloc() which could lead to a NULL pointer dereference. Standardize this by replacing malloc() with xmalloc() for error handling. To improve maintainability, use sizeof(*temp) instead of the struct name, and drop the typecast of void pointer assignment. Signed-off-by: Siddharth Shrimali <r.siddharth.shrimali@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 67ad421 commit 35f220b

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

builtin/submodule--helper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ static void submodule_summary_callback(struct diff_queue_struct *q,
10591059

10601060
if (!S_ISGITLINK(p->one->mode) && !S_ISGITLINK(p->two->mode))
10611061
continue;
1062-
temp = (struct module_cb*)malloc(sizeof(struct module_cb));
1062+
temp = xmalloc(sizeof(*temp));
10631063
temp->mod_src = p->one->mode;
10641064
temp->mod_dst = p->two->mode;
10651065
temp->oid_src = p->one->oid;

0 commit comments

Comments
 (0)