[PATCH] fix git alias
From: Junio C Hamano <hidden>
Date: 2016-06-15 22:42:29
Subsystem:
the rest · Maintainer:
Linus Torvalds
When extra command line arguments are given to a command that was alias-expanded, the code generated a wrong argument list, leaving the original alias in the result, and forgetting to terminate the new argv list. Signed-off-by: Junio C Hamano <redacted> --- * This would make "git l -n 4" work when you have "alias.l = log -M" in your configuration. The original code generated an equivalent of "git log -M l -n 4". There is another more grave problem I seem to be hitting but haven't figured out (and will probably not figure out while away); I'd appreciate if you can track it down. With "alias.wh = whatchanged --patch-with-stat", "git wh HEAD -- mailinfo.c" segfaults at fclose() in git_config_from_file() when it reads the configuration for the second time (the first time being getting the alias). The second call comes via init_revisions() calling setup_git_directory(). Oddly I do not seem to be able to reproduce this segfault on amd64.
diff --git a/git.c b/git.c
index 9469d44..329ebec 100644
--- a/git.c
+++ b/git.c@@ -122,9 +122,9 @@ static int handle_alias(int *argcp, cons /* insert after command name */ if (*argcp > 1) { new_argv = realloc(new_argv, sizeof(char*) * - (count + *argcp - 1)); - memcpy(new_argv + count, *argv, sizeof(char*) * - (*argcp - 1)); + (count + *argcp)); + memcpy(new_argv + count, *argv + 1, + sizeof(char*) * *argcp); } *argv = new_argv;