From: Junio C Hamano Date: Fri, 10 Dec 2010 17:30:45 GMT Subject: Re: [PATCH v4 1/3] fetch/pull: Add the --recurse-submodules option Message-ID: <7vlj3xedru.fsf@alter.siamese.dyndns.org> In-Reply-To: <4D016146.9010907@web.de> Jens Lehmann writes: > Am 09.12.2010 22:16, schrieb Junio C Hamano: > ... >>> +int fetch_populated_submodules(int num_options, const char **options, >>> + const char *prefix, int quiet) >>> +{ >>> + int i, result = 0, argc = 0; >>> + struct child_process cp; >>> + const char **argv; >>> + struct string_list_item *name_for_path; >>> + const char *work_tree = get_git_work_tree(); >>> + if (!work_tree) >>> + return 0; >>> + >>> + if (!the_index.initialized) >>> + if (read_cache() < 0) >>> + die("index file corrupt"); >>> + >>> + argv = xcalloc(num_options + 5, sizeof(const char *)); >> >> Where is this '5' coming from? "fetch" "--submodule-prefix", the prefix, >> and the terminating NULL? What did I miss? > > No, you didn't miss anything but I have been off by one ... '4' is > sufficient here. Ok, thanks for double checking. -- >8 -- Subject: [PATCH] fetch_populated_submodules(): document dynamic allocation size ... while fixing a miscounting. Signed-off-by: Junio C Hamano --- submodule.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/submodule.c b/submodule.c index 4e62900..6f1c107 100644 --- a/submodule.c +++ b/submodule.c @@ -264,7 +264,8 @@ int fetch_populated_submodules(int num_options, const char **options, if (read_cache() < 0) die("index file corrupt"); - argv = xcalloc(num_options + 5, sizeof(const char *)); + /* 4: "fetch" (options) "--submodule-prefix" prefix NULL */ + argv = xcalloc(num_options + 4, sizeof(const char *)); argv[argc++] = "fetch"; for (i = 0; i < num_options; i++) argv[argc++] = options[i];