rm: remove unneeded null pointer check
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Stefan Beller committed
Aug 8, 2013 at 19:52 UTC
f8aae0b51743d5e5f35292caee41e5215b0e5bad
1 file changed
+17
-21
builtin/rm.c
+17
-21
@@ -277,8 +277,8 @@ static struct option builtin_rm_options[] = {
277
278
int cmd_rm(int argc, const char **argv, const char *prefix)
279
{
280
- int i, newfd;
281
- const char **pathspec;
280
+ int i, newfd, seen_any;
281
+ const char **pathspec, *match;
282
char *seen;
283
284
git_config(git_default_config, NULL);
@@ -314,7 +314,6 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
314
pathspec = get_pathspec(prefix, argv);
315
refresh_index(&the_index, REFRESH_QUIET, pathspec, NULL, NULL);
316
317
- seen = NULL;
317
for (i = 0; pathspec[i] ; i++)
318
/* nothing */;
319
seen = xcalloc(i, 1);
@@ -328,27 +327,24 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
327
list.entry[list.nr++].is_submodule = S_ISGITLINK(ce->ce_mode);
328
}
329
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);
337
}
344
- if (!recursive && seen[i] == MATCHED_RECURSIVELY)
345
- die(_("not removing '%s' recursively without -r"),
346
- *match ? match : ".");
338
}
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 : ".");
345
}
346
+ if (!seen_any)
347
+ exit(0);
348
349
/*
350
* If not forced, the file, the index and the HEAD (if exists)