public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] submodule--helper: replace malloc with xmalloc
@ 2026-03-10 12:10 Siddharth Shrimali
  2026-03-10 12:22 ` Patrick Steinhardt
  2026-03-10 16:03 ` Junio C Hamano
  0 siblings, 2 replies; 5+ messages in thread
From: Siddharth Shrimali @ 2026-03-10 12:10 UTC (permalink / raw)
  To: git; +Cc: gitster, ps, r.siddharth.shrimali

The submodule_summary_callback() function currently uses a raw malloc()
which could lead to NULL pointer dereference.

Standardize this by replacing malloc() with xmalloc() for error handling.
Also, remove the unnecessary type cast and use sizeof(*temp) instead of
struct name in xmalloc to improve maintainability of the code.

Signed-off-by: Siddharth Shrimali <r.siddharth.shrimali@gmail.com>
---
 builtin/submodule--helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 143f7cb3cc..f3e132888f 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1160,7 +1160,7 @@ static void submodule_summary_callback(struct diff_queue_struct *q,
 
 		if (!S_ISGITLINK(p->one->mode) && !S_ISGITLINK(p->two->mode))
 			continue;
-		temp = (struct module_cb*)malloc(sizeof(struct module_cb));
+		temp = xmalloc(sizeof(*temp));
 		temp->mod_src = p->one->mode;
 		temp->mod_dst = p->two->mode;
 		temp->oid_src = p->one->oid;
-- 
2.51.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-03-10 19:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-10 12:10 [PATCH] submodule--helper: replace malloc with xmalloc Siddharth Shrimali
2026-03-10 12:22 ` Patrick Steinhardt
2026-03-10 16:03 ` Junio C Hamano
2026-03-10 16:44   ` [PATCH v2] " Siddharth Shrimali
2026-03-10 19:35     ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox