git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [BUG] revision: premature free-and-null causes “unknown option `(null)`”

From
Jeff King <peff@peff.net>
Date
Sep 25, 2026, 08:26 UTC
Message-ID
<20260925082636.GA1493716@coredump.intra.peff.net>
In-Reply-To
<74796901-ffb1-4cf3-bd63-7294328f70bc@app.fastmail.com>
On Fri, Sep 25, 2026 at 02:28:57AM +0200, Kristoffer Haugsbakk wrote:
Show 9 quoted lines
> git shortlog -n --not-an-option master
> [...]
>
> I expected it to print the option in quotes. Instead it printed `(null)`
> which I think is the placeholder for when the `%s` arg is `NULL`.
> [...]
> 
> I have bisected this to cd439487 (revision: manage memory ownership of
> argv in setup_revisions(), 2025-09-19).

Yep, definitely my fault. I don't have time to do a full write-up now, but the most direct solution is:

diff --git a/revision.c b/revision.c
index ee1df92d1d..501a4ba36e 100644
--- a/revision.c
+++ b/revision.c
@@ -2768,13 +2768,13 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
 void parse_revision_opt(struct rev_info *revs, struct parse_opt_ctx_t *ctx,
 			const struct option *options,
 			const char * const usagestr[])
 {
 	int n = handle_revision_opt(revs, ctx->argc, ctx->argv,
 				    &ctx->cpidx, ctx->out, NULL);
 	if (n <= 0) {
-		error("unknown option `%s'", ctx->argv[0]);
+		error("unknown option `%s'", ctx->out[ctx->cpidx - 1]);
 		usage_with_options(usagestr, options);
 	}
 	ctx->argv += n;
 	ctx->argc -= n;
 }

But I think instead doing this:

diff --git a/revision.c b/revision.c
index ee1df92d1d..7b858d54c1 100644
--- a/revision.c
+++ b/revision.c
@@ -2340,7 +2340,8 @@ static void overwrite_argv(int *argc, const char **argv,
 	if (*value != argv[*argc]) {
 		mark_argv_for_free(opt, revs, argv[*argc]);
 		argv[*argc] = *value;
-		*value = NULL;
+		if (opt && opt->free_removed_argv_elements)
+			*value = NULL;
 	}
 	(*argc)++;
 }

will restore some of the hidden assumptions made by pre-cd439487 code.
So it would fix this case, along with any other lurkers.

I know that's probably quite opaque. ;) I'll fully explain what's going
on in a follow-up tomorrow, but I wanted to post the solution quickly so
nobody else wasted time digging.

Thanks for a clear report.

-Peff
Previous: Kristoffer HaugsbakkNext: Jeff King
Message 2 of 9 in “[BUG] revision: premature free-and-null causes “unknown option `(null)`””
  1. Kristoffer HaugsbakkSep 25, 2026
  2. Jeff KingSep 25, 2026
  3. 0/2 some parse_revision_opt() bugfixesJeff King, Sep 25, 2026
  4. 1/2 revision: avoid reporting known options as unknown on errorJeff King, Sep 25, 2026
  5. 2/2 revision: handle argv movement in parse_revision_opt()Jeff King, Sep 25, 2026
  6. Kristoffer HaugsbakkSep 26, 2026
  7. Jeff KingSep 28, 2026
  8. Kristoffer HaugsbakkSep 29, 2026
  9. Junio C HamanoSep 25, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.