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
This commit is contained in:
Junio C Hamano 2013-09-04 12:36:30 -07:00
commit 2bdd8727d7
2 changed files with 21 additions and 25 deletions

View File

@ -277,8 +277,8 @@ static struct option builtin_rm_options[] = {
int cmd_rm(int argc, const char **argv, const char *prefix) int cmd_rm(int argc, const char **argv, const char *prefix)
{ {
int i, newfd; int i, newfd, seen_any;
const char **pathspec; const char **pathspec, *match;
char *seen; char *seen;
git_config(git_default_config, NULL); 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); pathspec = get_pathspec(prefix, argv);
refresh_index(&the_index, REFRESH_QUIET, pathspec, NULL, NULL); refresh_index(&the_index, REFRESH_QUIET, pathspec, NULL, NULL);
seen = NULL;
for (i = 0; pathspec[i] ; i++) for (i = 0; pathspec[i] ; i++)
/* nothing */; /* nothing */;
seen = xcalloc(i, 1); 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); 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;
}
if (!recursive && seen[i] == MATCHED_RECURSIVELY)
die(_("not removing '%s' recursively without -r"),
*match ? match : ".");
}
if (! seen_any) seen_any = 0;
exit(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;
}
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) * If not forced, the file, the index and the HEAD (if exists)

6
diff.c
View File

@ -669,7 +669,7 @@ static void emit_rewrite_diff(const char *name_a,
memset(&ecbdata, 0, sizeof(ecbdata)); memset(&ecbdata, 0, sizeof(ecbdata));
ecbdata.color_diff = want_color(o->use_color); ecbdata.color_diff = want_color(o->use_color);
ecbdata.found_changesp = &o->found_changes; ecbdata.found_changesp = &o->found_changes;
ecbdata.ws_rule = whitespace_rule(name_b ? name_b : name_a); ecbdata.ws_rule = whitespace_rule(name_b);
ecbdata.opt = o; ecbdata.opt = o;
if (ecbdata.ws_rule & WS_BLANK_AT_EOF) { if (ecbdata.ws_rule & WS_BLANK_AT_EOF) {
mmfile_t mf1, mf2; mmfile_t mf1, mf2;
@ -2252,7 +2252,7 @@ static void builtin_diff(const char *name_a,
(!two->mode || S_ISGITLINK(two->mode))) { (!two->mode || S_ISGITLINK(two->mode))) {
const char *del = diff_get_color_opt(o, DIFF_FILE_OLD); const char *del = diff_get_color_opt(o, DIFF_FILE_OLD);
const char *add = diff_get_color_opt(o, DIFF_FILE_NEW); const char *add = diff_get_color_opt(o, DIFF_FILE_NEW);
show_submodule_summary(o->file, one ? one->path : two->path, show_submodule_summary(o->file, one->path ? one->path : two->path,
line_prefix, line_prefix,
one->sha1, two->sha1, two->dirty_submodule, one->sha1, two->sha1, two->dirty_submodule,
meta, del, add, reset); meta, del, add, reset);
@ -2372,7 +2372,7 @@ static void builtin_diff(const char *name_a,
ecbdata.label_path = lbl; ecbdata.label_path = lbl;
ecbdata.color_diff = want_color(o->use_color); ecbdata.color_diff = want_color(o->use_color);
ecbdata.found_changesp = &o->found_changes; ecbdata.found_changesp = &o->found_changes;
ecbdata.ws_rule = whitespace_rule(name_b ? name_b : name_a); ecbdata.ws_rule = whitespace_rule(name_b);
if (ecbdata.ws_rule & WS_BLANK_AT_EOF) if (ecbdata.ws_rule & WS_BLANK_AT_EOF)
check_blank_at_eof(&mf1, &mf2, &ecbdata); check_blank_at_eof(&mf1, &mf2, &ecbdata);
ecbdata.opt = o; ecbdata.opt = o;