@@ -346,23 +346,22 @@ int finish_async(struct async *async)
346
346
int run_hook (const char * index_file , const char * name , ...)
347
347
{
348
348
struct child_process hook ;
349
- const char * argv [ 10 ] , * env [2 ];
349
+ const char * * argv = NULL , * env [2 ];
350
350
char index [PATH_MAX ];
351
351
va_list args ;
352
352
int ret ;
353
- int i ;
353
+ size_t i = 0 , alloc = 0 ;
354
354
355
355
if (access (git_path ("hooks/%s" , name ), X_OK ) < 0 )
356
356
return 0 ;
357
357
358
358
va_start (args , name );
359
- argv [0 ] = git_path ("hooks/%s" , name );
360
- i = 0 ;
361
- do {
362
- if (++ i >= ARRAY_SIZE (argv ))
363
- die ("run_hook(): too many arguments" );
364
- argv [i ] = va_arg (args , const char * );
365
- } while (argv [i ]);
359
+ ALLOC_GROW (argv , i + 1 , alloc );
360
+ argv [i ++ ] = git_path ("hooks/%s" , name );
361
+ while (argv [i - 1 ]) {
362
+ ALLOC_GROW (argv , i + 1 , alloc );
363
+ argv [i ++ ] = va_arg (args , const char * );
364
+ }
366
365
va_end (args );
367
366
368
367
memset (& hook , 0 , sizeof (hook ));
@@ -377,6 +376,7 @@ int run_hook(const char *index_file, const char *name, ...)
377
376
}
378
377
379
378
ret = start_command (& hook );
379
+ free (argv );
380
380
if (ret ) {
381
381
warning ("Could not spawn %s" , argv [0 ]);
382
382
return ret ;
0 commit comments