public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Collin Funk <collin.funk1@gmail.com>
Cc: git@vger.kernel.org,  Jeff King <peff@peff.net>,
	 Taylor Blau <me@ttaylorr.com>,  Elijah Newren <newren@gmail.com>
Subject: Re: [PATCH] global: constify some pointers that are not written to
Date: Thu, 05 Feb 2026 09:49:32 -0800	[thread overview]
Message-ID: <xmqqecmzm66r.fsf@gitster.g> (raw)
In-Reply-To: <342b01acd42f1fcaa3abefa38dc589e12ccb1134.1770261829.git.collin.funk1@gmail.com> (Collin Funk's message of "Wed, 4 Feb 2026 19:24:19 -0800")

Collin Funk <collin.funk1@gmail.com> writes:

> This patch fixes the more obvious ones by making them const when we do
> not write to the returned pointer.
>
> Signed-off-by: Collin Funk <collin.funk1@gmail.com>
> ---
>  add-patch.c                    | 2 +-
>  apply.c                        | 2 +-
>  builtin/commit.c               | 2 +-
>  builtin/receive-pack.c         | 2 +-
>  builtin/remote.c               | 2 +-
> ...
>  wrapper.c                      | 2 +-
>  28 files changed, 34 insertions(+), 31 deletions(-)

Indeed, the number of files makes it look worse than it really is.

> diff --git a/pkt-line.c b/pkt-line.c
> index fc583feb26..3fc3e9ea70 100644
> --- a/pkt-line.c
> +++ b/pkt-line.c
> @@ -384,10 +384,10 @@ int packet_length(const char lenbuf_hex[4], size_t size)
>  		hexval(lenbuf_hex[3]);
>  }
>  
> -static char *find_packfile_uri_path(const char *buffer)
> +static const char *find_packfile_uri_path(const char *buffer)
>  {
>  	const char *URI_MARK = "://";
> -	char *path;
> +	const char *path;
>  	int len;
>  
>  	/* First char is sideband mark */

Everything other than this hunk is adding "const" to local pointers
and compilers will complain if we depended on them being writable,
so this is an easy patch to review.  We can trust even this hunk to
compilers, as the callers of this function would be flagged if they
tried to write through the return value from it.

Looking good.  I agree with Peff that the removal of unused NULL
initialization would have been much better done in a separate patch.

Thanks.

  parent reply	other threads:[~2026-02-05 17:49 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-05  3:24 [PATCH] global: constify some pointers that are not written to Collin Funk
2026-02-05  7:41 ` Jeff King
2026-02-05 17:49 ` Junio C Hamano [this message]
2026-02-05 22:00   ` Collin Funk
2026-02-06  1:46 ` [PATCH v2 1/2] " Collin Funk
2026-02-06  1:46   ` [PATCH v2 2/2] gpg-interface: remove an unnecessary NULL initialization Collin Funk
2026-02-06  1:59     ` Junio C Hamano
2026-02-06 15:54   ` [PATCH v2 1/2] global: constify some pointers that are not written to Ben Knoble

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=xmqqecmzm66r.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=collin.funk1@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=me@ttaylorr.com \
    --cc=newren@gmail.com \
    --cc=peff@peff.net \
    /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