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

Re: [PATCH 1/4] git-commit: support variable number of hook arguments

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 5, 2008, 03:09 UTC
Message-ID
<7vejbsgkup.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<alpine.LSU.1.00.0802041637460.7372@racer.site>
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
Show 31 quoted lines
> Hi,
>
> On Mon, 21 Jan 2008, Paolo Bonzini wrote:
>
>> +static int run_hook(const char *index_file, const char *name, ...)
>> +{
>> +	struct child_process hook;
>> +	const char *argv[10], *env[2];
>> +	char index[PATH_MAX];
>> +	va_list args;
>> +	int i;
>> +
>> +	va_start(args, name);
>> +	argv[0] = git_path("hooks/%s", name);
>> +	i = 0;
>> +	do {
>
> Here, an
>
> 		if (++i >= ARRAY_SIZE(argv))
> 			die ("run_hook(): too many arguments");
>
> is missing.  Even nicer, you could have
>
> 	int argc = 1;
> 	char **argv = malloc(sizeof(*argv) * 2);
>
> and
>
> 		if (++i >= argc)
> 			argc = ALLOC_GROW(argv, i + 1, argc);

The sanity check to make sure we do not feed too many is definitely needed. For this application I think ALLOC_GROW() is overkill, as we do not pass unbound number of arguments to the hook.

Previous: Johannes SchindelinNext: Paolo Bonzini
Message 4 of 13 in “git-commit: add a prepare-commit-msg hook”
  1. git-commit: add a prepare-commit-msg hookPaolo Bonzini, Jan 21, 2008
  2. 1/4 git-commit: support variable number of hook argumentsPaolo Bonzini, Jan 21, 2008
  3. Johannes SchindelinFeb 4, 2008
  4. Junio C HamanoFeb 5, 2008
  5. 2/4 git-commit: set GIT_EDITOR=: if editor will not be launchedPaolo Bonzini, Jan 21, 2008
  6. 4/4 git-commit: add a prepare-commit-msg hookPaolo Bonzini, Jan 21, 2008
  7. Junio C HamanoFeb 5, 2008
  8. 3/4 git-commit: Refactor creation of log message.Paolo Bonzini, Jan 21, 2008
  9. Johannes SchindelinFeb 4, 2008
  10. Paolo BonziniFeb 4, 2008
  11. Junio C HamanoFeb 5, 2008
  12. Junio C HamanoFeb 5, 2008
  13. Paolo BonziniFeb 5, 2008

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.