Skip to content

Commit 2bdd872

Browse files
committed
Merge branch 'sb/misc-cleanup'
* sb/misc-cleanup: rm: remove unneeded null pointer check diff: fix a possible null pointer dereference diff: remove ternary operator evaluating always to true
2 parents 05584b2 + f8aae0b commit 2bdd872

File tree

2 files changed

+20
-24
lines changed

2 files changed

+20
-24
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)

diff.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ static void emit_rewrite_diff(const char *name_a,
669669
memset(&ecbdata, 0, sizeof(ecbdata));
670670
ecbdata.color_diff = want_color(o->use_color);
671671
ecbdata.found_changesp = &o->found_changes;
672-
ecbdata.ws_rule = whitespace_rule(name_b ? name_b : name_a);
672+
ecbdata.ws_rule = whitespace_rule(name_b);
673673
ecbdata.opt = o;
674674
if (ecbdata.ws_rule & WS_BLANK_AT_EOF) {
675675
mmfile_t mf1, mf2;
@@ -2252,7 +2252,7 @@ static void builtin_diff(const char *name_a,
22522252
(!two->mode || S_ISGITLINK(two->mode))) {
22532253
const char *del = diff_get_color_opt(o, DIFF_FILE_OLD);
22542254
const char *add = diff_get_color_opt(o, DIFF_FILE_NEW);
2255-
show_submodule_summary(o->file, one ? one->path : two->path,
2255+
show_submodule_summary(o->file, one->path ? one->path : two->path,
22562256
line_prefix,
22572257
one->sha1, two->sha1, two->dirty_submodule,
22582258
meta, del, add, reset);
@@ -2372,7 +2372,7 @@ static void builtin_diff(const char *name_a,
23722372
ecbdata.label_path = lbl;
23732373
ecbdata.color_diff = want_color(o->use_color);
23742374
ecbdata.found_changesp = &o->found_changes;
2375-
ecbdata.ws_rule = whitespace_rule(name_b ? name_b : name_a);
2375+
ecbdata.ws_rule = whitespace_rule(name_b);
23762376
if (ecbdata.ws_rule & WS_BLANK_AT_EOF)
23772377
check_blank_at_eof(&mf1, &mf2, &ecbdata);
23782378
ecbdata.opt = o;

0 commit comments

Comments
 (0)