Skip to content

Commit

Permalink
merge-recursive: add some defensive coding to was_dirty()
Browse files Browse the repository at this point in the history
It took this developer quite a good while to understand why the current
code cannot get a `NULL` returned by `index_file_exists()`. To
un-confuse readers (and future-proof the code), let's just be safe and
check before we dereference the returned pointer.
  • Loading branch information
dscho authored and derrickstolee committed Aug 31, 2022
1 parent 6c9e24f commit b664fc5
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion merge-recursive.c
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ static int was_dirty(struct merge_options *opt, const char *path)

ce = index_file_exists(opt->priv->unpack_opts.src_index,
path, strlen(path), ignore_case);
return verify_uptodate(ce, &opt->priv->unpack_opts) != 0;
return !ce || verify_uptodate(ce, &opt->priv->unpack_opts) != 0;
}

static int make_room_for_path(struct merge_options *opt, const char *path)
Expand Down

0 comments on commit b664fc5

Please sign in to comment.