]> git.ipfire.org Git - thirdparty/git.git/commitdiff
pager: explicitly cast away strchr() constness
authorJeff King <peff@peff.net>
Thu, 2 Apr 2026 04:14:58 +0000 (00:14 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 2 Apr 2026 05:08:51 +0000 (22:08 -0700)
When we do:

  char *cp = strchr(argv[i], '=');

it implicitly removes the constness from argv[i]. We need "cp" to remain
writable (since we overwrite it with a NUL). In theory we should be able
to drop the const from argv[i], because it is a sub-pointer into our
duplicated pager_env variable.

But we get it from split_cmdline(), which uses the traditional "const
char **" type for argv. This is overly limiting, but changing it would
be awkward for all the other callers of split_cmdline().

Let's do an explicit cast with a note about why it is OK. This is enough
to silence compiler warnings about the implicit const problems.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
pager.c

diff --git a/pager.c b/pager.c
index 5531fff50eb73f7d22defcc7d8e752c94f741d66..35b210e0484f90c3c2439b84c11aad2012e67747 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -108,10 +108,11 @@ const char *git_pager(struct repository *r, int stdout_is_tty)
 
 static void setup_pager_env(struct strvec *env)
 {
-       const char **argv;
+       char **argv;
        int i;
        char *pager_env = xstrdup(PAGER_ENV);
-       int n = split_cmdline(pager_env, &argv);
+       /* split_cmdline splits in place, so we know the result is writable */
+       int n = split_cmdline(pager_env, (const char ***)&argv);
 
        if (n < 0)
                die("malformed build-time PAGER_ENV: %s",