From: Junio C Hamano Date: Tue, 05 Feb 2008 03:09:34 GMT Subject: Re: [PATCH 1/4] git-commit: support variable number of hook arguments Message-ID: <7vejbsgkup.fsf@gitster.siamese.dyndns.org> In-Reply-To: Johannes Schindelin writes: > 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.