fix: coverity warnings (#3168)

* fix: uninitialized peer_atom field

* fix: silence inaccurate open-files-test warning

* fix: assertion-is-always-true

asserting unsigned val is >= 0

* fix: unnecessary nullptr check

* fix: nullptr dereference warning
This commit is contained in:
Charles Kerr 2022-05-31 18:58:20 -05:00 committed by GitHub
parent 1c3d60fcd5
commit 84d65d8e61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 5 additions and 9 deletions

View File

@ -94,10 +94,7 @@ bool favicon_web_done_idle_cb(std::unique_ptr<favicon_data> fav)
}
// Not released into the next web request, means we're done trying (even if `pixbuf` is still invalid)
if (fav != nullptr)
{
fav->func(pixbuf);
}
fav->func(pixbuf);
return false;
}

View File

@ -704,7 +704,7 @@ static ReadState readPeerId(tr_handshake* handshake, struct evbuffer* inbuf)
// if we've somehow connected to ourselves, don't keep the connection
auto const hash = tr_peerIoGetTorrentHash(handshake->io);
auto* const tor = hash ? handshake->session->torrents().get(*hash) : nullptr;
bool const connected_to_self = peer_id == tr_torrentGetPeerId(tor);
bool const connected_to_self = tor != nullptr && peer_id == tr_torrentGetPeerId(tor);
return tr_handshakeDone(handshake, !connected_to_self);
}

View File

@ -229,7 +229,7 @@ struct peer_atom
time_t lastConnectionAttemptAt = {};
time_t lastConnectionAt = {};
tr_peer* peer; /* will be nullptr if not connected */
tr_peer* peer = nullptr; // will be nullptr if not connected
uint8_t const fromFirst; /* where the peer was first found */
uint8_t fromBest; /* the "best" value of where the peer has been found */
@ -2308,7 +2308,6 @@ static void removePeer(tr_peer* peer)
--s->stats.peer_from_count[atom->fromFirst];
TR_ASSERT(s->stats.peer_count == s->peerCount());
TR_ASSERT(s->stats.peer_from_count[atom->fromFirst] >= 0);
delete peer;
}

View File

@ -42,8 +42,8 @@ TEST_F(OpenFilesTest, getOpensIfNotCached)
auto buf = std::array<char, std::size(Contents) + 1>{};
auto bytes_read = uint64_t{};
EXPECT_TRUE(tr_sys_file_read_at(*fd, std::data(buf), std::size(Contents), 0, &bytes_read));
buf[bytes_read] = '\0';
EXPECT_EQ(Contents, (char*)std::data(buf));
auto const contents = std::string_view{ std::data(buf), static_cast<size_t>(bytes_read) };
EXPECT_EQ(Contents, contents);
}
TEST_F(OpenFilesTest, getCacheSucceedsIfCached)