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.