{"thread":{"id":"30199","subject":"[PATCH] test-subprocess: fix segfault without arguments","startedAt":"2012-04-10T19:07:34Z","lastAt":"2012-04-10T19:07:34Z","messageCount":1,"participants":["René Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"188900","messageId":"4F8484F6.8000206@lsrfire.ath.cx","threadId":"30199","inReplyTo":null,"subject":"[PATCH] test-subprocess: fix segfault without arguments","fromName":"René Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2012-04-10T19:07:34Z","receivedAt":"2012-04-10T19:07:34Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Check if we even have a parameter before checking its value.  Running\nthis command without any arguments may not make a lot of sense, but\nreacting with a segmentation fault is unduly harsh.\n\nWhile we're at it, avoid casting argv by declaring it const right away.\n\nSigned-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>\n---\n test-subprocess.c |    6 +++---\n 1 file changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/test-subprocess.c b/test-subprocess.c\nindex 8926bc5..f2d4c0d 100644\n--- a/test-subprocess.c\n+++ b/test-subprocess.c\n@@ -1,7 +1,7 @@\n #include \"cache.h\"\n #include \"run-command.h\"\n \n-int main(int argc, char **argv)\n+int main(int argc, const char **argv)\n {\n \tstruct child_process cp;\n \tint nogit = 0;\n@@ -9,12 +9,12 @@ int main(int argc, char **argv)\n \tsetup_git_directory_gently(&nogit);\n \tif (nogit)\n \t\tdie(\"No git repo found\");\n-\tif (!strcmp(argv[1], \"--setup-work-tree\")) {\n+\tif (argc > 1 && !strcmp(argv[1], \"--setup-work-tree\")) {\n \t\tsetup_work_tree();\n \t\targv++;\n \t}\n \tmemset(&cp, 0, sizeof(cp));\n \tcp.git_cmd = 1;\n-\tcp.argv = (const char **)argv+1;\n+\tcp.argv = argv + 1;\n \treturn run_command(&cp);\n }\n-- \n1.7.10\n"}]}