git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Beller <stefanbeller@googlemail.com>
To: git@vger.kernel.org, gitster@pobox.com
Cc: Stefan Beller <stefanbeller@googlemail.com>
Subject: [PATCH] rm: remove unneeded null pointer check
Date: Thu,  8 Aug 2013 19:52:41 +0200	[thread overview]
Message-ID: <1375984361-2494-1-git-send-email-stefanbeller@googlemail.com> (raw)

As of 7612a1efdb (2006-06-09 git-rm: honor -n flag.) the variable
'pathspec' seems to be assumed to be never NULL after calling get_pathspec
There was a NULL pointer check after the seen = NULL assignment, which
was removed by that commit. So if pathspec would be NULL now, we'd segfault
in the line accessing the pathspec:
	for (i = 0; pathspec[i] ; i++)

A few lines later, 'pathspec' still cannot be NULL, but that check was
overlooked, hence removing it now.

As the null pointer check was removed, it makes no sense to assign NULL
to seen and 3 lines later another value as there are no conditions in
between.

Signed-off-by: Stefan Beller <stefanbeller@googlemail.com>
---
 builtin/rm.c | 38 +++++++++++++++++---------------------
 1 file changed, 17 insertions(+), 21 deletions(-)

diff --git a/builtin/rm.c b/builtin/rm.c
index 0df0b4d..d00eaf8 100644
--- a/builtin/rm.c
+++ b/builtin/rm.c
@@ -277,8 +277,8 @@ static struct option builtin_rm_options[] = {
 
 int cmd_rm(int argc, const char **argv, const char *prefix)
 {
-	int i, newfd;
-	const char **pathspec;
+	int i, newfd, seen_any;
+	const char **pathspec, *match;
 	char *seen;
 
 	git_config(git_default_config, NULL);
@@ -314,7 +314,6 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
 	pathspec = get_pathspec(prefix, argv);
 	refresh_index(&the_index, REFRESH_QUIET, pathspec, NULL, NULL);
 
-	seen = NULL;
 	for (i = 0; pathspec[i] ; i++)
 		/* nothing */;
 	seen = xcalloc(i, 1);
@@ -328,27 +327,24 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
 		list.entry[list.nr++].is_submodule = S_ISGITLINK(ce->ce_mode);
 	}
 
-	if (pathspec) {
-		const char *match;
-		int seen_any = 0;
-		for (i = 0; (match = pathspec[i]) != NULL ; i++) {
-			if (!seen[i]) {
-				if (!ignore_unmatch) {
-					die(_("pathspec '%s' did not match any files"),
-					    match);
-				}
-			}
-			else {
-				seen_any = 1;
+
+	seen_any = 0;
+	for (i = 0; (match = pathspec[i]) != NULL ; i++) {
+		if (!seen[i]) {
+			if (!ignore_unmatch) {
+				die(_("pathspec '%s' did not match any files"),
+				    match);
 			}
-			if (!recursive && seen[i] == MATCHED_RECURSIVELY)
-				die(_("not removing '%s' recursively without -r"),
-				    *match ? match : ".");
 		}
-
-		if (! seen_any)
-			exit(0);
+		else {
+			seen_any = 1;
+		}
+		if (!recursive && seen[i] == MATCHED_RECURSIVELY)
+			die(_("not removing '%s' recursively without -r"),
+			    *match ? match : ".");
 	}
+	if (!seen_any)
+		exit(0);
 
 	/*
 	 * If not forced, the file, the index and the HEAD (if exists)
-- 
1.8.4.rc1.25.gd121ba2

                 reply	other threads:[~2013-08-08 17:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1375984361-2494-1-git-send-email-stefanbeller@googlemail.com \
    --to=stefanbeller@googlemail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).