Merge pull request #3198 from libgit2/cmn/coverity A few fixes from Coverity
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
diff --git a/src/indexer.c b/src/indexer.c
index e39345c..ef2ac3c 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -822,7 +822,7 @@ static int resolve_deltas(git_indexer *idx, git_transfer_progress *stats)
progressed = 0;
non_null = 0;
git_vector_foreach(&idx->deltas, i, delta) {
- git_rawobj obj;
+ git_rawobj obj = {NULL};
if (!delta)
continue;
diff --git a/src/odb_pack.c b/src/odb_pack.c
index 1757cf9..735158d 100644
--- a/src/odb_pack.c
+++ b/src/odb_pack.c
@@ -383,7 +383,7 @@ static int pack_backend__read_internal(
git_odb_backend *backend, const git_oid *oid)
{
struct git_pack_entry e;
- git_rawobj raw;
+ git_rawobj raw = {NULL};
int error;
if ((error = pack_entry_find(&e, (struct pack_backend *)backend, oid)) < 0 ||
diff --git a/src/rebase.c b/src/rebase.c
index b636e79..8da7b4f 100644
--- a/src/rebase.c
+++ b/src/rebase.c
@@ -512,7 +512,7 @@ static int rebase_ensure_not_dirty(
git_tree *head = NULL;
git_index *index = NULL;
git_diff *diff = NULL;
- int error;
+ int error = 0;
if (check_index) {
if ((error = git_repository_head_tree(&head, repo)) < 0 ||
diff --git a/src/remote.c b/src/remote.c
index b7acbb9..63f6d34 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -869,7 +869,7 @@ int git_remote_download(git_remote *remote, const git_strarray *refspecs, const
{
int error = -1;
size_t i;
- git_vector refs, specs, *to_active;
+ git_vector *to_active, specs = GIT_VECTOR_INIT, refs = GIT_VECTOR_INIT;
const git_remote_callbacks *cbs = NULL;
assert(remote);
@@ -2451,7 +2451,8 @@ char *apply_insteadof(git_config *config, const char *url, int direction)
suffix_length = strlen(SUFFIX_PUSH) + 1;
}
- git_config_iterator_glob_new(&iter, config, regexp);
+ if (git_config_iterator_glob_new(&iter, config, regexp) < 0)
+ return NULL;
match_length = 0;
while (git_config_next(&entry, iter) == 0) {
diff --git a/src/transports/ssh.c b/src/transports/ssh.c
index 5c8545f..83af137 100644
--- a/src/transports/ssh.c
+++ b/src/transports/ssh.c
@@ -177,11 +177,12 @@ static int ssh_stream_write(
static void ssh_stream_free(git_smart_subtransport_stream *stream)
{
ssh_stream *s = (ssh_stream *)stream;
- ssh_subtransport *t = OWNING_SUBTRANSPORT(s);
- int ret;
+ ssh_subtransport *t;
- GIT_UNUSED(ret);
+ if (!stream)
+ return;
+ t = OWNING_SUBTRANSPORT(s);
t->current_stream = NULL;
if (s->channel) {
@@ -621,8 +622,7 @@ static int _git_ssh_setup_conn(
done:
if (error < 0) {
- if (*stream)
- ssh_stream_free(*stream);
+ ssh_stream_free(*stream);
if (session)
libssh2_session_free(session);