public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Jeff King <peff@peff•net>
To: Michael J Gruber <git@grubix•eu>
Cc: git@vger•kernel.org
Subject: Re: [PATCH 6/6] do not discard const: the ugly truth
Date: Thu, 26 Mar 2026 13:42:04 -0400	[thread overview]
Message-ID: <20260326174204.GC2447148@coredump.intra.peff.net> (raw)
In-Reply-To: <fe9c86af4825a81b2618ae8ffc8be12300058af2.1774537954.git.git@grubix.eu>

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/e6f7e2eddbc9aef1c21f661420a4b8cb9cd8e2c1.1770095829.git.collin.funk1@gmail.com/

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

  parent reply	other threads:[~2026-03-26 17:42 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-26 15:22 [PATCH 0/6] ISOC23: quell warnings on discarding const Michael J Gruber
2026-03-26 15:22 ` [PATCH 1/6] do not discard const: the simple cases Michael J Gruber
2026-03-26 17:34   ` Jeff King
2026-03-26 17:45     ` Junio C Hamano
2026-03-26 19:23       ` [PATCH] config: store allocated string in non-const pointer Jeff King
2026-03-26 15:22 ` [PATCH 2/6] do not discard const: make git-compat-util ISOC23-like Michael J Gruber
2026-03-26 15:22 ` [PATCH 3/6] do not discard const: adjust to non-const data types Michael J Gruber
2026-03-26 17:28   ` Junio C Hamano
2026-03-26 15:22 ` [PATCH 4/6] do not discard const: declare const where we stay const Michael J Gruber
2026-03-26 15:22 ` [PATCH 5/6] do not discard const: keep signature Michael J Gruber
2026-03-26 17:18   ` Junio C Hamano
2026-03-26 15:22 ` [PATCH 6/6] do not discard const: the ugly truth Michael J Gruber
2026-03-26 17:07   ` Junio C Hamano
2026-03-26 17:42   ` Jeff King [this message]
2026-03-26 19:02     ` [PATCH 0/4] fix const issues in revision parser Jeff King
2026-03-26 19:04       ` [PATCH 1/4] revision: make handle_dotdot() interface less confusing Jeff King
2026-03-26 19:28         ` Junio C Hamano
2026-03-26 23:14           ` Jeff King
2026-03-27 15:55             ` Junio C Hamano
2026-03-26 19:05       ` [PATCH 2/4] rev-parse: simplify dotdot parsing Jeff King
2026-03-26 19:13       ` [PATCH 3/4] revision: avoid writing to const string for parent marks Jeff King
2026-03-26 19:14       ` [PATCH 4/4] rev-parse: " Jeff King
2026-03-26 16:26 ` [PATCH 0/6] ISOC23: quell warnings on discarding const D. Ben Knoble
2026-03-27 17:45   ` Michael J Gruber

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260326174204.GC2447148@coredump.intra.peff.net \
    --to=peff@peff$(echo .)net \
    --cc=git@grubix$(echo .)eu \
    --cc=git@vger$(echo .)kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox