Skip to content

Commit f8aae0b

Browse files
stefanbellergitster
authored andcommitted
rm: remove unneeded null pointer check
As of 7612a1e (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3b0c18a commit f8aae0b

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

builtin/rm.c

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@ static struct option builtin_rm_options[] = {
277277

278278
int cmd_rm(int argc, const char **argv, const char *prefix)
279279
{
280-
int i, newfd;
281-
const char **pathspec;
280+
int i, newfd, seen_any;
281+
const char **pathspec, *match;
282282
char *seen;
283283

284284
git_config(git_default_config, NULL);
@@ -314,7 +314,6 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
314314
pathspec = get_pathspec(prefix, argv);
315315
refresh_index(&the_index, REFRESH_QUIET, pathspec, NULL, NULL);
316316

317-
seen = NULL;
318317
for (i = 0; pathspec[i] ; i++)
319318
/* nothing */;
320319
seen = xcalloc(i, 1);
@@ -328,27 +327,24 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
328327
list.entry[list.nr++].is_submodule = S_ISGITLINK(ce->ce_mode);
329328
}
330329

331-
if (pathspec) {
332-
const char *match;
333-
int seen_any = 0;
334-
for (i = 0; (match = pathspec[i]) != NULL ; i++) {
335-
if (!seen[i]) {
336-
if (!ignore_unmatch) {
337-
die(_("pathspec '%s' did not match any files"),
338-
match);
339-
}
340-
}
341-
else {
342-
seen_any = 1;
330+
331+
seen_any = 0;
332+
for (i = 0; (match = pathspec[i]) != NULL ; i++) {
333+
if (!seen[i]) {
334+
if (!ignore_unmatch) {
335+
die(_("pathspec '%s' did not match any files"),
336+
match);
343337
}
344-
if (!recursive && seen[i] == MATCHED_RECURSIVELY)
345-
die(_("not removing '%s' recursively without -r"),
346-
*match ? match : ".");
347338
}
348-
349-
if (! seen_any)
350-
exit(0);
339+
else {
340+
seen_any = 1;
341+
}
342+
if (!recursive && seen[i] == MATCHED_RECURSIVELY)
343+
die(_("not removing '%s' recursively without -r"),
344+
*match ? match : ".");
351345
}
346+
if (!seen_any)
347+
exit(0);
352348

353349
/*
354350
* If not forced, the file, the index and the HEAD (if exists)

0 commit comments

Comments
 (0)