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

Re: [PATCH] Reserve a slot for argv[0] in default_arg.

From
PUPetter Urkedal <urkedal@nbi.dk>
Date
Oct 4, 2009, 14:51 UTC
Message-ID
<20091004145141.GA16477@eideticdew.org>
In-Reply-To
<20091004133333.GA13894@sigill.intra.peff.net>
On 2009-10-04, Jeff King wrote:
> Thanks, your fix looks sane. But I am curious about whether we are
> triggering some glibc pickiness that is in your setup, or if we are
> somehow violating the assumption that we only ever look at
> default_arg[1] and beyond.

I had a look at parse-options.c. In parse_options_start, argv is assigned to ctx->out, which is overwritten from index 0 in parse_options_end. This will show the problem:

diff --git a/builtin-show-branch.c b/builtin-show-branch.c
index 3510a86..1c587ad 100644
--- a/builtin-show-branch.c
+++ b/builtin-show-branch.c
@@ -691,6 +691,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
                showbranch_use_color = git_use_color_default;
 
        /* If nothing is specified, try the default first */
+       printf("default_arg = %p\n", default_arg);
        if (ac == 1 && default_num) {
                ac = default_num + 1;
                av = default_arg - 1; /* ick; we would not address av[0] */
diff --git a/parse-options.c b/parse-options.c
index f559411..267e752 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -435,6 +435,7 @@ unknown:
 
 int parse_options_end(struct parse_opt_ctx_t *ctx)
 {
+       printf("Assigning to %p\n", ctx->out + ctx->cpidx);
        memmove(ctx->out + ctx->cpidx, ctx->argv, ctx->argc * sizeof(*ctx->out));
        ctx->out[ctx->cpidx + ctx->argc] = NULL;
        return ctx->cpidx + ctx->argc;
Previous: Petter Urkedal
Message 10 of 10 in “Reserve a slot for argv[0] in default_arg.”
  1. Reserve a slot for argv[0] in default_arg.Petter Urkedal, Oct 3, 2009
  2. Jeff KingOct 4, 2009
  3. Petter UrkedalOct 4, 2009
  4. Jeff KingOct 4, 2009
  5. Stephen BoydOct 4, 2009
  6. Junio C HamanoOct 4, 2009
  7. Petter UrkedalOct 5, 2009
  8. Jeff KingOct 5, 2009
  9. Petter UrkedalOct 5, 2009
  10. Petter UrkedalOct 4, 2009

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.