Subject: Re: [PATCH 6/6] do not discard const: the ugly truth

From: Jeff King <[email-masked]>
Date: Thu, 26 Mar 2026 13:42:04 -0400

On Thu, Mar 26, 2026 at 04:22:52PM +0100, Michael J Gruber wrote:

> ISOC23 reveals that we mutate argv strings in place. Confess to this
> with explicit casts.

Collin and I looked at this one a bit in the earlier thread:

  https://lore.kernel.org/git/e6f7[email-masked]/

I think it is technically legal to mutate argv strings (which is why
this doesn't segfault now), though I think we would prefer to treat them
as conceptually const. You do get a segfault with:

  handle_revision_arg("..HEAD", &revs, 0, 0);

which we fortunately never do (we do pass string literals, but never
with a range operator).

IMHO the right solution here is to teach the revision-parser not to
touch the incoming buffers. We do it only to tie off strings, which can
mostly be replaced with xmemdupz(). That's slightly less efficient, but
I don't think it would be measurable (it's one allocation that tends to
happen a handful of times per program execution, and the rest of the
parsing is going to allocate things like commit structs anyway).

I have some patches in that direction, but I haven't gotten around to
polishing them yet.

-Peff