From: Jeff King Date: Tue, 31 Mar 2026 23:42:20 GMT Subject: [PATCH 04/12] pager: explicitly cast away strchr() constness Message-ID: <20260331234220.GD2328529@coredump.intra.peff.net> In-Reply-To: <20260331233856.GA2327197@coredump.intra.peff.net> 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 --- pager.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pager.c b/pager.c index 5531fff50e..801ba392f2 100644 --- a/pager.c +++ b/pager.c @@ -118,7 +118,8 @@ static void setup_pager_env(struct strvec *env) split_cmdline_strerror(n)); for (i = 0; i < n; i++) { - char *cp = strchr(argv[i], '='); + /* we know this is writable because it was split from pager_env */ + char *cp = strchr((char *)argv[i], '='); if (!cp) die("malformed build-time PAGER_ENV"); -- 2.53.0.1136.gd760fbd4a0