summaryrefslogtreecommitdiff
path: root/git.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2011-05-24 22:50:35 (GMT)
committerJunio C Hamano <gitster@pobox.com>2011-05-24 23:25:46 (GMT)
commit73546c085d49694c5e54b421f80bde6bc25006fb (patch)
tree5c1ad80fbf8fb766ab25de47819c3a46b4c1c758 /git.c
parent06eb708f331f0829081f4f3fb3c465eaae345deb (diff)
downloadgit-73546c085d49694c5e54b421f80bde6bc25006fb.zip
git-73546c085d49694c5e54b421f80bde6bc25006fb.tar.gz
git-73546c085d49694c5e54b421f80bde6bc25006fb.tar.bz2
handle_options(): do not miscount how many arguments were used
The handle_options() function advances the base of the argument array and returns the number of arguments it used. The caller in handle_alias() wants to reallocate the argv array it passes to this function, and attempts to do so by subtracting the returned value to compensate for the change handle_options() makes to the new_argv. But handle_options() did not correctly count when "-c <config=value>" is given, causing a wrong pointer to be passed to realloc(). Fix it by saving the original argv at the beginning of handle_options(), and return the difference between the final value of argv, which will relieve the places that move the array pointer from the additional burden of keeping track of "handled" counter. Noticed-by: Kazuki Tsujimoto Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git.c')
-rw-r--r--git.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/git.c b/git.c
index 6793178..6bea8ee 100644
--- a/git.c
+++ b/git.c
@@ -55,7 +55,7 @@ static void commit_pager_choice(void) {
static int handle_options(const char ***argv, int *argc, int *envchanged)
{
- int handled = 0;
+ const char **orig_argv = *argv;
while (*argc > 0) {
const char *cmd = (*argv)[0];
@@ -105,7 +105,6 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
*envchanged = 1;
(*argv)++;
(*argc)--;
- handled++;
} else if (!prefixcmp(cmd, "--git-dir=")) {
setenv(GIT_DIR_ENVIRONMENT, cmd + 10, 1);
if (envchanged)
@@ -145,9 +144,8 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
(*argv)++;
(*argc)--;
- handled++;
}
- return handled;
+ return (*argv) - orig_argv;
}
static int handle_alias(int *argcp, const char ***argv)