git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] Handle invalid argc gently

From
Dmitry V. Levin <ldv@altlinux.org>
Date
Sep 14, 2006, 01:04 UTC
Message-ID
<20060914010409.GB20593@nomad.office.altlinux.org>

describe, git: Handle argc==0 case the same way as argc==1. merge-tree: Refuse excessive arguments.

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
---
 describe.c   |    2 +-
 git.c        |    2 +-
 merge-tree.c |    2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/describe.c b/describe.c
index 5ed052d..2172e8f 100644
--- a/describe.c
+++ b/describe.c
@@ -163,7 +163,7 @@ int main(int argc, char **argv)
 
 	setup_git_directory();
 
-	if (i == argc)
+	if (i >= argc)
 		describe("HEAD", 1);
 	else
 		while (i < argc) {
diff --git a/git.c b/git.c
index 47c85e1..8c182a5 100644
--- a/git.c
+++ b/git.c
@@ -294,7 +294,7 @@ static void handle_internal_command(int 
 
 int main(int argc, const char **argv, char **envp)
 {
-	const char *cmd = argv[0];
+	const char *cmd = argv[0] ? argv[0] : "git-help";
 	char *slash = strrchr(cmd, '/');
 	const char *exec_path = NULL;
 	int done_alias = 0;
diff --git a/merge-tree.c b/merge-tree.c
index c154dcf..692ede0 100644
--- a/merge-tree.c
+++ b/merge-tree.c
@@ -337,7 +337,7 @@ int main(int argc, char **argv)
 	struct tree_desc t[3];
 	void *buf1, *buf2, *buf3;
 
-	if (argc < 4)
+	if (argc != 4)
 		usage(merge_tree_usage);
 
 	setup_git_directory();
-- 
ldv
Next: Junio C Hamano
Message 1 of 7 in “Handle invalid argc gently”
  1. 2/2 Handle invalid argc gentlyDmitry V. Levin, Sep 14, 2006
  2. Junio C HamanoSep 14, 2006
  3. Dmitry V. LevinSep 14, 2006
  4. Junio C HamanoSep 14, 2006
  5. Dmitry V. LevinSep 14, 2006
  6. Junio C HamanoSep 14, 2006
  7. Dmitry V. LevinSep 14, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.