summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 06eb708)
raw | patch | inline | side by side (parent: 06eb708)
author | Junio C Hamano <gitster@pobox.com> | |
Tue, 24 May 2011 22:50:35 +0000 (18:50 -0400) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Tue, 24 May 2011 23:25:46 +0000 (16:25 -0700) |
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>
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>
git.c | patch | blob | history | |
t/t1300-repo-config.sh | patch | blob | history |
index 6793178210db64ae59d3a4d401f32d6d3bd5b1a1..6bea8eeaacb4858bcf6c93de4c609c5d9574b946 100644 (file)
--- a/git.c
+++ b/git.c
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];
*envchanged = 1;
(*argv)++;
(*argc)--;
- handled++;
} else if (!prefixcmp(cmd, "--git-dir=")) {
setenv(GIT_DIR_ENVIRONMENT, cmd + 10, 1);
if (envchanged)
(*argv)++;
(*argc)--;
- handled++;
}
- return handled;
+ return (*argv) - orig_argv;
}
static int handle_alias(int *argcp, const char ***argv)
diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh
index 52c9ac9b65393dceb21551b8fdb9a14c19c3b48e..de2a014d8fade18d8e8f666c502e584a57473d28 100755 (executable)
--- a/t/t1300-repo-config.sh
+++ b/t/t1300-repo-config.sh
test_must_fail git -c core.name=value config name
'
-test_expect_failure 'git -c works with aliases of builtins' '
+test_expect_success 'git -c works with aliases of builtins' '
git config alias.checkconfig "-c foo.check=bar config foo.check" &&
echo bar >expect &&
git checkconfig >actual &&