Skip to content

Commit a961d1f

Browse files
René Scharfegitster
authored andcommitted
test-subprocess: fix segfault without arguments
Check if we even have a parameter before checking its value. Running this command without any arguments may not make a lot of sense, but reacting with a segmentation fault is unduly harsh. While we're at it, avoid casting argv by declaring it const right away. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c2df758 commit a961d1f

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

test-subprocess.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
#include "cache.h"
22
#include "run-command.h"
33

4-
int main(int argc, char **argv)
4+
int main(int argc, const char **argv)
55
{
66
struct child_process cp;
77
int nogit = 0;
88

99
setup_git_directory_gently(&nogit);
1010
if (nogit)
1111
die("No git repo found");
12-
if (!strcmp(argv[1], "--setup-work-tree")) {
12+
if (argc > 1 && !strcmp(argv[1], "--setup-work-tree")) {
1313
setup_work_tree();
1414
argv++;
1515
}
1616
memset(&cp, 0, sizeof(cp));
1717
cp.git_cmd = 1;
18-
cp.argv = (const char **)argv+1;
18+
cp.argv = argv + 1;
1919
return run_command(&cp);
2020
}

0 commit comments

Comments
 (0)