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

Re: [PATCH] rev-parse: Check argc before using argv[i+1]

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 28, 2014, 19:12 UTC
Message-ID
<xmqqtxcnly39.fsf@gitster.dls.corp.google.com>
In-Reply-To
<1390866262-10188-1-git-send-email-dhsharp@google.com>
David Sharp <dhsharp@google.com> writes:
Show 11 quoted lines
> @@ -738,9 +740,11 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
>  				continue;
>  			}
>  			if (!strcmp(arg, "--resolve-git-dir")) {
> -				const char *gitdir = resolve_gitdir(argv[i+1]);
> +				if (++i >= argc)
> +					die("--resolve-git-dir requires an argument");
> +				const char *gitdir = resolve_gitdir(argv[i]);
>  				if (!gitdir)
> -					die("not a gitdir '%s'", argv[i+1]);
> +					die("not a gitdir '%s'", argv[i]);

This adds decl-after-statement. As referencing argv[argc] is not a crime (you will grab a NULL), how about doing it this way to see if the value is a NULL, instead of comparing the index and argc?

	const char *gitdir;
        if (!argv[++i])
        	die("--resolve-git-dir requires an argument");
	gitdir = resolve_gitdir(argv[i]);
        if (!gitdir)
        	die("not a gitdir '%s'", argv[i]);
Same comment may apply to other hunks.
Thanks.
Previous: David SharpNext: David Sharp
Message 2 of 8 in “rev-parse: Check argc before using argv[i+1]”
  1. rev-parse: Check argc before using argv[i+1]David Sharp, Jan 27, 2014
  2. Junio C HamanoJan 28, 2014
  3. David SharpJan 28, 2014
  4. rev-parse: Check argc before using argv[i+1]David Sharp, Jan 28, 2014
  5. Junio C HamanoJan 28, 2014
  6. David SharpJan 28, 2014
  7. Johannes SixtJan 28, 2014
  8. David SharpJan 28, 2014

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.