git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 5, 2026, 17:49 UTC
Message-ID
<xmqqecmzm66r.fsf@gitster.g>
In-Reply-To
<342b01acd42f1fcaa3abefa38dc589e12ccb1134.1770261829.git.collin.funk1@gmail.com>
Collin Funk <collin.funk1@gmail.com> writes:
Show 13 quoted lines
> 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.
Show 17 quoted lines
> 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.
Previous: Jeff KingNext: Collin Funk
Message 3 of 8 in “global: constify some pointers that are not written to”
  1. global: constify some pointers that are not written toCollin Funk, Feb 5, 2026
  2. Jeff KingFeb 5, 2026
  3. Junio C HamanoFeb 5, 2026
  4. Collin FunkFeb 5, 2026
  5. 1/2 global: constify some pointers that are not written toCollin Funk, Feb 6, 2026
  6. 2/2 gpg-interface: remove an unnecessary NULL initializationCollin Funk, Feb 6, 2026
  7. Junio C HamanoFeb 6, 2026
  8. Ben KnobleFeb 6, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.