Merge pull request #2847 from jacquesg/coverity More coverity fixes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
diff --git a/src/diff_patch.c b/src/diff_patch.c
index 3129d06..a151077 100644
--- a/src/diff_patch.c
+++ b/src/diff_patch.c
@@ -823,7 +823,8 @@ int git_patch__invoke_callbacks(
for (i = 0; !error && i < git_array_size(patch->hunks); ++i) {
diff_patch_hunk *h = git_array_get(patch->hunks, i);
- error = hunk_cb(patch->delta, &h->hunk, payload);
+ if (hunk_cb)
+ error = hunk_cb(patch->delta, &h->hunk, payload);
if (!line_cb)
continue;
diff --git a/src/index.c b/src/index.c
index 079b0cb..cbace36 100644
--- a/src/index.c
+++ b/src/index.c
@@ -292,6 +292,9 @@ static void index_entry_reuc_free(git_index_reuc_entry *reuc)
static void index_entry_free(git_index_entry *entry)
{
+ if (!entry)
+ return;
+
memset(&entry->id, 0, sizeof(entry->id));
git__free(entry);
}
diff --git a/src/pathspec.c b/src/pathspec.c
index 6aef574..fab6f9a 100644
--- a/src/pathspec.c
+++ b/src/pathspec.c
@@ -318,6 +318,9 @@ static git_pathspec_match_list *pathspec_match_alloc(
m = NULL;
}
+ if (!m)
+ return NULL;
+
/* need to keep reference to pathspec and increment refcount because
* failures array stores pointers to the pattern strings of the
* pathspec that had no matches