git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] [Outreachy] patch-ids: fix const correctness
Date: Mon, 13 Oct 2025 10:12:00 -0700	[thread overview]
Message-ID: <xmqq4is23evz.fsf@gitster.g> (raw)
In-Reply-To: <20251013165320.201333-1-okhuomonajayi54@gmail.com> (Okhuomon Ajayi's message of "Mon, 13 Oct 2025 17:53:20 +0100")

Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:

> The `patch_id_neq()` function received a pointer to diff options via
> `cmpfn_data` but cast it to a non-const type. This caused a const
> correctness warning and could potentially allow unintended modification
> of read-only data.
>
> Fix this by casting to `const struct diff_options *` instead, removing
> the outdated NEEDSWORK comment in the process.
>
> Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
> ---
>  patch-ids.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/patch-ids.c b/patch-ids.c
> index a5683b462c..b6b808332f 100644
> --- a/patch-ids.c
> +++ b/patch-ids.c
> @@ -41,8 +41,8 @@ static int patch_id_neq(const void *cmpfn_data,
>  			const struct hashmap_entry *entry_or_key,
>  			const void *keydata UNUSED)
>  {
> -	/* NEEDSWORK: const correctness? */
> -	struct diff_options *opt = (void *)cmpfn_data;
> +	

Trailing whitespace on this line.  Remove the entire line instead.

> +	const struct diff_options *opt = (void *)cmpfn_data;
>  	struct patch_id *a, *b;
>  
>  	a = container_of(eptr, struct patch_id, ent);

I do not think this is correct.  Have you even compile-tested this
patch?

Later in this same function, opt is passed to commit_patch_id()
function (twice), which takes non-const "struct diff_options *" that
is given to diffcore_std().  And the last function in this callchain
has to modify the structure to record various findings (like "did we
see any changes in the diff?"), so it cannot be "const" at all.

I think patch_id_neq() that says cmpfn_data is const is the source
of the problem, but that function signature is mandated by the
hashmap API.  I do not know if we can loosen it there in the hashmap
API and if so what the argument would be, but thinking about these
things is what the NEEDSWORK comment is about ;-).




  reply	other threads:[~2025-10-13 17:12 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-13 16:53 [PATCH] [Outreachy] patch-ids: fix const correctness Okhuomon Ajayi
2025-10-13 17:12 ` Junio C Hamano [this message]
2025-10-13 17:22   ` Okhuomon Ajayi
2025-10-13 17:29     ` Junio C Hamano
2025-10-13 18:14       ` Okhuomon Ajayi
2025-10-13 18:33         ` Junio C Hamano
2025-10-13 21:55           ` Okhuomon Ajayi
  -- strict thread matches above, loose matches on Subject: below --
2025-10-09 21:44 Okhuomon Ajayi
2025-10-09 21:46 ` Kristoffer Haugsbakk
2025-10-10  0:45   ` Junio C Hamano
2025-10-09 21:57 ` Okhuomon Ajayi
2025-10-09 23:49   ` Agatha Isabelle
2025-10-10  0:13     ` Okhuomon Ajayi

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=xmqq4is23evz.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=okhuomonajayi54@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).