All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Siddharth Shrimali <r.siddharth.shrimali@gmail.com>
Cc: git@vger.kernel.org,  ps@pks.im
Subject: Re: [PATCH v2] submodule--helper: replace malloc with xmalloc
Date: Tue, 10 Mar 2026 12:35:05 -0700	[thread overview]
Message-ID: <xmqqo6kvtr4m.fsf@gitster.g> (raw)
In-Reply-To: <20260310164412.47403-1-r.siddharth.shrimali@gmail.com> (Siddharth Shrimali's message of "Tue, 10 Mar 2026 22:14:12 +0530")

Siddharth Shrimali <r.siddharth.shrimali@gmail.com> writes:

> 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.
>
> While at it, ...

I think use of sizeof(*temp) and dropping of a cast from (void *)
fall into the same bucket, i.e. to improve maintainability.  Both
are good changes.

> 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));

Looking good.

Thanks.

      reply	other threads:[~2026-03-10 19:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqo6kvtr4m.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=ps@pks.im \
    --cc=r.siddharth.shrimali@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.