Subject: Re: [PATCH] global: constify some pointers that are not written to

From: Junio C Hamano <[email-masked]>
Date: Thu, 05 Feb 2026 09:49:32 -0800

Collin Funk <[email-masked]> 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 <[email-masked]>
> ---
>  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.