Commit 349532d0b1fd4eb94b398616602674ff516f6d76

Brandon Casey 2011-11-06T19:44:29

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
diff --git a/examples/network/git2.c b/examples/network/git2.c
index a4bff4a..def56e8 100644
--- a/examples/network/git2.c
+++ b/examples/network/git2.c
@@ -45,6 +45,7 @@ int main(int argc, char **argv)
 
 	if (argc < 2) {
 		fprintf(stderr, "usage: %s <cmd> [repo]\n", argv[0]);
+		exit(EXIT_FAILURE);
 	}
 
 	for (i = 0; commands[i].name != NULL; ++i) {
@@ -53,5 +54,5 @@ int main(int argc, char **argv)
 	}
 
 	fprintf(stderr, "Command not found: %s\n", argv[1]);
-  
+	return 1;
 }