From: Junio C Hamano Date: Tue, 28 Jan 2014 19:12:42 GMT Subject: Re: [PATCH] rev-parse: Check argc before using argv[i+1] Message-ID: In-Reply-To: <1390866262-10188-1-git-send-email-dhsharp@google.com> David Sharp writes: > @@ -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.