Commit 349532d0 by Brandon Casey

examples/network/git2.c: exit with proper status, and avoid segfault

This function should exit after printing usage information if too few
arguments were specified.

Additionally, it should exit with a failure status if the first argument
supplied is not one in the internal command list.
parent 983562e4
...@@ -45,6 +45,7 @@ int main(int argc, char **argv) ...@@ -45,6 +45,7 @@ int main(int argc, char **argv)
if (argc < 2) { if (argc < 2) {
fprintf(stderr, "usage: %s <cmd> [repo]\n", argv[0]); fprintf(stderr, "usage: %s <cmd> [repo]\n", argv[0]);
exit(EXIT_FAILURE);
} }
for (i = 0; commands[i].name != NULL; ++i) { for (i = 0; commands[i].name != NULL; ++i) {
...@@ -53,5 +54,5 @@ int main(int argc, char **argv) ...@@ -53,5 +54,5 @@ int main(int argc, char **argv)
} }
fprintf(stderr, "Command not found: %s\n", argv[1]); fprintf(stderr, "Command not found: %s\n", argv[1]);
return 1;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment