diff --git a/gtk/FaviconCache.cc b/gtk/FaviconCache.cc index 190ee0c91..93d9df554 100644 --- a/gtk/FaviconCache.cc +++ b/gtk/FaviconCache.cc @@ -94,10 +94,7 @@ bool favicon_web_done_idle_cb(std::unique_ptr 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; } diff --git a/libtransmission/handshake.cc b/libtransmission/handshake.cc index 0b6525506..ad4bbd253 100644 --- a/libtransmission/handshake.cc +++ b/libtransmission/handshake.cc @@ -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); } diff --git a/libtransmission/peer-mgr.cc b/libtransmission/peer-mgr.cc index 508c224a8..1ea3c7ae3 100644 --- a/libtransmission/peer-mgr.cc +++ b/libtransmission/peer-mgr.cc @@ -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; } diff --git a/tests/libtransmission/open-files-test.cc b/tests/libtransmission/open-files-test.cc index 1f4aa97e2..acee35cab 100644 --- a/tests/libtransmission/open-files-test.cc +++ b/tests/libtransmission/open-files-test.cc @@ -42,8 +42,8 @@ TEST_F(OpenFilesTest, getOpensIfNotCached) auto buf = std::array{}; 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(bytes_read) }; + EXPECT_EQ(Contents, contents); } TEST_F(OpenFilesTest, getCacheSucceedsIfCached)