fix some warnings around unused variables, dead stores, potentially dereferencing nullptr and calling virtual functions from constructor

This commit is contained in:
arvidn 2018-07-19 14:27:12 +02:00 committed by Arvid Norberg
parent d8755066e8
commit e92cf18340
6 changed files with 17 additions and 18 deletions

View File

@ -516,9 +516,9 @@ namespace aux {
int est_reciprocation_rate() const { return m_est_reciprocation_rate; } int est_reciprocation_rate() const { return m_est_reciprocation_rate; }
#ifndef TORRENT_DISABLE_LOGGING #ifndef TORRENT_DISABLE_LOGGING
bool should_log(peer_log_alert::direction_t direction) const override; bool should_log(peer_log_alert::direction_t direction) const override final;
void peer_log(peer_log_alert::direction_t direction void peer_log(peer_log_alert::direction_t direction
, char const* event, char const* fmt, ...) const noexcept override TORRENT_FORMAT(4,5); , char const* event, char const* fmt, ...) const noexcept override final TORRENT_FORMAT(4,5);
void peer_log(peer_log_alert::direction_t direction void peer_log(peer_log_alert::direction_t direction
, char const* event) const noexcept; , char const* event) const noexcept;

View File

@ -453,7 +453,7 @@ void node::announce(sha1_hash const& info_hash, int listen_port, announce_flags_
} }
#endif #endif
if (listen_port == 0) if (listen_port == 0 && m_observer != nullptr)
{ {
listen_port = m_observer->get_listen_port( listen_port = m_observer->get_listen_port(
flags & announce::ssl_torrent ? aux::transport::ssl : aux::transport::plaintext flags & announce::ssl_torrent ? aux::transport::ssl : aux::transport::plaintext

View File

@ -5893,7 +5893,7 @@ namespace libtorrent {
if (buffer_size > 0) if (buffer_size > 0)
{ {
span<char> const vec = m_recv_buffer.reserve(buffer_size); span<char> const vec = m_recv_buffer.reserve(buffer_size);
std::size_t bytes = m_socket->read_some( std::size_t const bytes = m_socket->read_some(
boost::asio::mutable_buffers_1(vec.data(), vec.size()), ec); boost::asio::mutable_buffers_1(vec.data(), vec.size()), ec);
// this is weird. You would imagine read_some() would do this // this is weird. You would imagine read_some() would do this
@ -5908,14 +5908,14 @@ namespace libtorrent {
#endif #endif
TORRENT_ASSERT(bytes > 0 || ec); TORRENT_ASSERT(bytes > 0 || ec);
if (ec == boost::asio::error::would_block || ec == boost::asio::error::try_again) if (ec)
{ {
bytes = 0; if (ec != boost::asio::error::would_block
} && ec != boost::asio::error::try_again)
else if (ec) {
{ disconnect(ec, operation_t::sock_read);
disconnect(ec, operation_t::sock_read); return;
return; }
} }
else else
{ {

View File

@ -84,7 +84,7 @@ void resolve_links::match(std::shared_ptr<const torrent_info> const& ti
std::int64_t const file_size = fs.file_size(i); std::int64_t const file_size = fs.file_size(i);
auto range = m_file_sizes.equal_range(file_size); auto const range = m_file_sizes.equal_range(file_size);
for (auto iter = range.first; iter != range.second; ++iter) for (auto iter = range.first; iter != range.second; ++iter)
{ {
TORRENT_ASSERT(iter->second >= file_index_t(0)); TORRENT_ASSERT(iter->second >= file_index_t(0));

View File

@ -1793,8 +1793,6 @@ bool utp_socket_impl::send_pkt(int const flags)
return false; return false;
} }
int packet_size = header_size + payload_size;
packet_ptr p; packet_ptr p;
std::uint8_t* ptr = nullptr; std::uint8_t* ptr = nullptr;
utp_header* h = nullptr; utp_header* h = nullptr;
@ -1810,6 +1808,7 @@ bool utp_socket_impl::send_pkt(int const flags)
m_sm.inc_stats_counter(counters::utp_payload_pkts_out); m_sm.inc_stats_counter(counters::utp_payload_pkts_out);
} }
int const packet_size = header_size + payload_size;
p->size = std::uint16_t(packet_size); p->size = std::uint16_t(packet_size);
p->header_size = std::uint16_t(packet_size - payload_size); p->header_size = std::uint16_t(packet_size - payload_size);
p->num_transmissions = 0; p->num_transmissions = 0;
@ -1883,7 +1882,6 @@ bool utp_socket_impl::send_pkt(int const flags)
return false; return false;
} }
packet_size = p->size;
payload_size = p->size - p->header_size; payload_size = p->size - p->header_size;
} }
@ -2572,7 +2570,7 @@ bool utp_socket_impl::test_socket_state()
return false; return false;
} }
void utp_socket_impl::init_mtu(int link_mtu, int utp_mtu) void utp_socket_impl::init_mtu(int const link_mtu, int utp_mtu)
{ {
INVARIANT_CHECK; INVARIANT_CHECK;
@ -2580,9 +2578,8 @@ void utp_socket_impl::init_mtu(int link_mtu, int utp_mtu)
{ {
// we can't use larger packets than this since we're // we can't use larger packets than this since we're
// not allocating any more memory for socket buffers // not allocating any more memory for socket buffers
int decrease = link_mtu - TORRENT_ETHERNET_MTU; int const decrease = link_mtu - TORRENT_ETHERNET_MTU;
utp_mtu -= decrease; utp_mtu -= decrease;
link_mtu -= decrease;
} }
// set the ceiling to what we found out from the interface // set the ceiling to what we found out from the interface

View File

@ -433,6 +433,7 @@ void test_iovec()
TEST_SETUP; TEST_SETUP;
ret = bc.allocate_iovec(iov); ret = bc.allocate_iovec(iov);
TEST_EQUAL(ret, 0);
bc.free_iovec(iov); bc.free_iovec(iov);
} }
@ -505,6 +506,7 @@ TORRENT_TEST(delete_piece)
rj.storage = pm; rj.storage = pm;
rj.argument = remove_flags_t{}; rj.argument = remove_flags_t{};
ret = bc.try_read(&rj, alloc); ret = bc.try_read(&rj, alloc);
TEST_EQUAL(ret, -1);
cached_piece_entry* pe_ = bc.find_piece(pm.get(), piece_index_t(0)); cached_piece_entry* pe_ = bc.find_piece(pm.get(), piece_index_t(0));
bc.mark_for_eviction(pe_, block_cache::disallow_ghost); bc.mark_for_eviction(pe_, block_cache::disallow_ghost);