Skip to content

Commit 6167c13

Browse files
drafnelgitster
authored andcommitted
git.c: avoid allocating one-too-many elements for new argv array
When creating a new argv array from a configured alias and the supplied command line arguments, the new argv was allocated with one element too many. Since the first element of the original argv array is skipped when copying it to the new_argv, the number of elements that are allocated should be reduced by one. 'count' is the number of elements that new_argv contains, and *argcp is the number of elements in the original argv array. So the total allocation (including the terminating NULL entry) for the new_argv array should be: count + (*argcp - 1) + 1 Also, the explicit assignment of the NULL terminating entry can be avoided by just copying it over from the original argv array. Signed-off-by: Brandon Casey <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b8f2626 commit 6167c13

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

git.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,9 @@ static int handle_alias(int *argcp, const char ***argv)
188188
alias_command);
189189

190190
new_argv = xrealloc(new_argv, sizeof(char *) *
191-
(count + *argcp + 1));
191+
(count + *argcp));
192192
/* insert after command name */
193193
memcpy(new_argv + count, *argv + 1, sizeof(char *) * *argcp);
194-
new_argv[count+*argcp] = NULL;
195194

196195
*argv = new_argv;
197196
*argcp += count - 1;

0 commit comments

Comments
 (0)