]> Kevux Git Server - rit/commit
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)
commit031d29d6fbf12284d391c23f04d15970c3bac11c
treec67407c135c12c1dac1137421aace5a3ee73a0bd
parenteedc7ecc66aefa085aae9bf51b56aa11eeb23950
pager: explicitly cast away strchr() constness

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