Re: [PATCH 04/12] pager: explicitly cast away strchr() constness
- From
Jeff King <peff@peff.net>
- Date
- Apr 2, 2026, 03:54 UTC
- Message-ID
- <20260402035409.GA3492642@coredump.intra.peff.net>
- In-Reply-To
- <xmqqh5puv20c.fsf@gitster.g>
On Wed, Apr 01, 2026 at 01:50:27PM -0700, Junio C Hamano wrote:
Show 20 quoted lines
> Jeff King <peff@peff.net> writes: > > > 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(). > > Yeah, it was the first thing that came to my mind that const char > **argv is the source of the problem. We could cast the pointer we > give to split_cmdline() and drop const from argv[] instead, which > may make the in-code comment unnecessary but the patch we see here > is good enough.
Ooh, that is a good idea. It puts the cast closer to the actual root cause. I think there are one or two other touch-ups, so I'll include that in a v2.
-Peff