diff --git a/Jamfile b/Jamfile index 9b195f6aa..f4cdec328 100644 --- a/Jamfile +++ b/Jamfile @@ -242,10 +242,6 @@ rule warnings ( properties * ) # this warns on any global static object, which are used for error_category # objects result += -Wno-exit-time-destructors ; - result += -Wno-unused-command-line-argument ; - result += -Wno-implicit-fallthrough ; - result += -Wno-c++11-long-long ; - result += -Wno-variadic-macros ; # enable these warnings again, once the other ones are dealt with result += -Wno-weak-vtables ; diff --git a/include/libtorrent/aux_/file_progress.hpp b/include/libtorrent/aux_/file_progress.hpp index 4943b690f..eaa4924ee 100644 --- a/include/libtorrent/aux_/file_progress.hpp +++ b/include/libtorrent/aux_/file_progress.hpp @@ -74,7 +74,7 @@ namespace aux // this lets us trigger on individual files completing // the vector is allocated lazily, when file progress // is first queried by the client - std::vector m_file_progress; + std::vector m_file_progress; #if TORRENT_USE_INVARIANT_CHECKS friend class libtorrent::invariant_access; @@ -85,10 +85,9 @@ namespace aux // to make sure we never say we've downloaded more bytes of a file than // its file size - std::vector m_file_sizes; + std::vector m_file_sizes; #endif }; } } #endif - diff --git a/include/libtorrent/peer_class_set.hpp b/include/libtorrent/peer_class_set.hpp index 54fc42334..e9e9865f9 100644 --- a/include/libtorrent/peer_class_set.hpp +++ b/include/libtorrent/peer_class_set.hpp @@ -56,7 +56,7 @@ namespace libtorrent { private: // the number of elements used in the m_class array - std::uint8_t m_size; + std::int8_t m_size; // if this object belongs to any peer-class, this vector contains all // class IDs. Each ID refers to a an entry in m_ses.m_peer_classes which diff --git a/src/file_progress.cpp b/src/file_progress.cpp index a2dd73d1b..d56ef0e95 100644 --- a/src/file_progress.cpp +++ b/src/file_progress.cpp @@ -68,8 +68,8 @@ namespace libtorrent { namespace aux // initialize the progress of each file int const piece_size = fs.piece_length(); - std::uint64_t off = 0; - std::uint64_t const total_size = fs.total_size(); + std::int64_t off = 0; + std::int64_t const total_size = fs.total_size(); int file_index = 0; for (int piece = 0; piece < num_pieces; ++piece, off += piece_size) { @@ -92,7 +92,7 @@ namespace libtorrent { namespace aux #endif TORRENT_ASSERT(total_size >= off); - std::int64_t size = (std::min)(std::uint64_t(piece_size), total_size - off); + std::int64_t size = (std::min)(std::int64_t(piece_size), total_size - off); TORRENT_ASSERT(size >= 0); while (size) @@ -126,7 +126,8 @@ namespace libtorrent { namespace aux void file_progress::clear() { INVARIANT_CHECK; - std::vector().swap(m_file_progress); + m_file_progress.clear(); + m_file_progress.shrink_to_fit(); #if TORRENT_USE_INVARIANT_CHECKS m_have_pieces.clear(); #endif @@ -187,12 +188,10 @@ namespace libtorrent { namespace aux if (m_file_progress.empty()) return; int index = 0; - for (std::uint64_t progress : m_file_progress) + for (std::int64_t progress : m_file_progress) { TORRENT_ASSERT(progress <= m_file_sizes[index++]); } } #endif } } - - diff --git a/src/kademlia/dht_storage.cpp b/src/kademlia/dht_storage.cpp index bb4013c64..6a14e585e 100644 --- a/src/kademlia/dht_storage.cpp +++ b/src/kademlia/dht_storage.cpp @@ -229,6 +229,7 @@ namespace { tcp const protocol = requester.is_v4() ? tcp::v4() : tcp::v6(); int to_pick = m_settings.max_peers_reply; + TORRENT_ASSERT(to_pick >= 0); // if these are IPv6 peers their addresses are 4x the size of IPv4 // so reduce the max peers 4 fold to compensate // max_peers_reply should probably be specified in bytes @@ -239,7 +240,7 @@ namespace int candidates = int(std::count_if(peersv.begin(), peersv.end() , [=](peer_entry const& e) { return !(noseed && e.seed); })); - to_pick = (std::min)(to_pick, candidates); + to_pick = std::min(to_pick, candidates); for (auto iter = peersv.begin(); to_pick > 0; ++iter) { @@ -251,7 +252,7 @@ namespace // pick this peer with probability // / - if (random(uint32_t(candidates--)) > to_pick) + if (random(std::uint32_t(candidates--)) > std::uint32_t(to_pick)) continue; pe.push_back(entry()); @@ -320,7 +321,7 @@ namespace { *i = peer; } - else if (peersv.size() >= m_settings.max_peers) + else if (int(peersv.size()) >= m_settings.max_peers) { // we're at capacity, drop the announce return; diff --git a/src/kademlia/item.cpp b/src/kademlia/item.cpp index ae3e0cddb..16fae5bc1 100644 --- a/src/kademlia/item.cpp +++ b/src/kademlia/item.cpp @@ -74,7 +74,7 @@ namespace left = out.size() - (ptr - out.data()); std::memcpy(ptr, v.data(), std::min(v.size(), left)); ptr += std::min(v.size(), left); - TORRENT_ASSERT((ptr - out.data()) <= out.size()); + TORRENT_ASSERT((ptr - out.data()) <= int(out.size())); return ptr - out.data(); } } diff --git a/src/kademlia/node.cpp b/src/kademlia/node.cpp index c5fb4942e..89b77f690 100644 --- a/src/kademlia/node.cpp +++ b/src/kademlia/node.cpp @@ -597,9 +597,8 @@ struct ping_observer : observer } // look for nodes -#if TORRENT_USE_IPV6 - udp protocol = algorithm()->get_node().protocol(); -#endif + udp const protocol = algorithm()->get_node().protocol(); + int const protocol_size = int(detail::address_size(protocol)); char const* nodes_key = algorithm()->get_node().protocol_nodes_key(); bdecode_node n = r.dict_find_string(nodes_key); if (n) @@ -607,7 +606,7 @@ struct ping_observer : observer char const* nodes = n.string_ptr(); char const* end = nodes + n.string_length(); - while (end - nodes >= 20 + detail::address_size(protocol) + 2) + while (end - nodes >= 20 + protocol_size + 2) { node_id id; std::copy(nodes, nodes + 20, id.begin()); @@ -1063,7 +1062,7 @@ void node::incoming_request(msg const& m, entry& e) // number matches the expected value before replacing it // this is critical for avoiding race conditions when multiple // writers are accessing the same slot - if (msg_keys[5] && item_seq.value != msg_keys[5].int_value()) + if (msg_keys[5] && item_seq.value != std::uint64_t(msg_keys[5].int_value())) { m_counters.inc_stats_counter(counters::dht_invalid_put); incoming_error(e, "CAS mismatch", 301); diff --git a/src/kademlia/routing_table.cpp b/src/kademlia/routing_table.cpp index a83040824..c6280e80b 100644 --- a/src/kademlia/routing_table.cpp +++ b/src/kademlia/routing_table.cpp @@ -370,7 +370,7 @@ void routing_table::fill_from_replacements(table_t::iterator bucket) bucket_t& rb = bucket->replacements; int const bucket_size = bucket_limit(std::distance(m_buckets.begin(), bucket)); - if (b.size() >= bucket_size) return; + if (int(b.size()) >= bucket_size) return; // sort by RTT first, to find the node with the lowest // RTT that is pinged @@ -378,7 +378,7 @@ void routing_table::fill_from_replacements(table_t::iterator bucket) , [](node_entry const& lhs, node_entry const& rhs) { return lhs.rtt < rhs.rtt; }); - while (b.size() < bucket_size && !rb.empty()) + while (int(b.size()) < bucket_size && !rb.empty()) { bucket_t::iterator j = std::find_if(rb.begin(), rb.end(), std::bind(&node_entry::pinged, _1)); if (j == rb.end()) j = rb.begin(); @@ -440,7 +440,7 @@ bool routing_table::add_node(node_entry const& e) // if the new bucket still has too many nodes in it, we need to keep // splitting - if (m_buckets.back().live_nodes.size() > bucket_limit(int(m_buckets.size()) - 1)) + if (int(m_buckets.back().live_nodes.size()) > bucket_limit(int(m_buckets.size()) - 1)) continue; s = add_node_impl(e); @@ -734,7 +734,7 @@ ip_ok: // the last bucket is special, since it hasn't been split yet, it // includes that top bit as well int const prefix_offset = - bucket_index + 1 == m_buckets.size() ? bucket_index : bucket_index + 1; + bucket_index + 1 == int(m_buckets.size()) ? bucket_index : bucket_index + 1; { node_id id = e.id; @@ -910,7 +910,7 @@ void routing_table::split_bucket() j = b.erase(j); } - if (b.size() > bucket_size_limit) + if (int(b.size()) > bucket_size_limit) { // TODO: 2 move the lowest priority nodes to the replacement bucket for (bucket_t::iterator i = b.begin() + bucket_size_limit @@ -1212,7 +1212,7 @@ void routing_table::check_invariant() const } #endif -bool routing_table::is_full(int bucket) const +bool routing_table::is_full(int const bucket) const { int num_buckets = int(m_buckets.size()); if (num_buckets == 0) return false; @@ -1220,8 +1220,8 @@ bool routing_table::is_full(int bucket) const table_t::const_iterator i = m_buckets.begin(); std::advance(i, bucket); - return (i->live_nodes.size() >= bucket_limit(bucket) - && i->replacements.size() >= m_bucket_size); + return (int(i->live_nodes.size()) >= bucket_limit(bucket) + && int(i->replacements.size()) >= m_bucket_size); } } } // namespace libtorrent::dht diff --git a/src/kademlia/traversal_algorithm.cpp b/src/kademlia/traversal_algorithm.cpp index 5e71627d9..5ca81cf8a 100644 --- a/src/kademlia/traversal_algorithm.cpp +++ b/src/kademlia/traversal_algorithm.cpp @@ -592,9 +592,8 @@ void traversal_observer::reply(msg const& m) #endif // look for nodes -#if TORRENT_USE_IPV6 - udp protocol = algorithm()->get_node().protocol(); -#endif + udp const protocol = algorithm()->get_node().protocol(); + int const protocol_size = int(detail::address_size(protocol)); char const* nodes_key = algorithm()->get_node().protocol_nodes_key(); bdecode_node n = r.dict_find_string(nodes_key); if (n) @@ -602,7 +601,7 @@ void traversal_observer::reply(msg const& m) char const* nodes = n.string_ptr(); char const* end = nodes + n.string_length(); - while (end - nodes >= 20 + detail::address_size(protocol) + 2) + while (end - nodes >= 20 + protocol_size + 2) { node_id id; std::copy(nodes, nodes + 20, id.begin()); diff --git a/src/lazy_bdecode.cpp b/src/lazy_bdecode.cpp index d66f3c6c2..5cffdbbe9 100644 --- a/src/lazy_bdecode.cpp +++ b/src/lazy_bdecode.cpp @@ -411,7 +411,7 @@ namespace libtorrent for (int i = 0; i < int(m_size); ++i) { lazy_dict_entry& e = m_data.dict[i+1]; - if (name.size() != e.val.m_begin - e.name) continue; + if (int(name.size()) != e.val.m_begin - e.name) continue; if (std::equal(name.begin(), name.end(), e.name)) return &e.val; } @@ -661,4 +661,3 @@ namespace libtorrent } #endif // TORRENT_NO_DEPRECATE - diff --git a/src/performance_counters.cpp b/src/performance_counters.cpp index ee557172b..820cc20c5 100644 --- a/src/performance_counters.cpp +++ b/src/performance_counters.cpp @@ -43,7 +43,7 @@ namespace libtorrent { for (int i = 0; i < m_stats_counter.size(); ++i) m_stats_counter[i].store(0, std::memory_order_relaxed); #else - memset(m_stats_counter, 0, sizeof(m_stats_counter)); + std::memset(m_stats_counter, 0, sizeof(m_stats_counter)); #endif } @@ -56,7 +56,7 @@ namespace libtorrent { , std::memory_order_relaxed); #else std::lock_guard l(c.m_mutex); - memcpy(m_stats_counter, c.m_stats_counter, sizeof(m_stats_counter)); + std::memcpy(m_stats_counter, c.m_stats_counter, sizeof(m_stats_counter)); #endif } @@ -70,7 +70,7 @@ namespace libtorrent { #else std::lock_guard l(m_mutex); std::lock_guard l2(c.m_mutex); - memcpy(m_stats_counter, c.m_stats_counter, sizeof(m_stats_counter)); + std::memcpy(m_stats_counter, c.m_stats_counter, sizeof(m_stats_counter)); #endif return *this; } @@ -154,4 +154,3 @@ namespace libtorrent { } } - diff --git a/src/resolver.cpp b/src/resolver.cpp index e3dea47cc..7e0d617be 100644 --- a/src/resolver.cpp +++ b/src/resolver.cpp @@ -73,7 +73,7 @@ namespace libtorrent // if m_cache grows too big, weed out the // oldest entries - if (m_cache.size() > m_max_size) + if (int(m_cache.size()) > m_max_size) { cache_t::iterator oldest = m_cache.begin(); for (cache_t::iterator k = m_cache.begin(); diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 94177a42c..4ba50474f 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -2694,7 +2694,7 @@ namespace aux { } if (connection_limit_factor == 0) connection_limit_factor = 100; - std::uint64_t limit = m_settings.get_int(settings_pack::connections_limit); + std::int64_t limit = m_settings.get_int(settings_pack::connections_limit); limit = limit * 100 / connection_limit_factor; // don't allow more connections than the max setting @@ -6278,7 +6278,7 @@ namespace aux { // if we don't have any alerts in our local cache, we have to ask // the alert_manager for more. It will swap our vector with its and // destruct eny left-over alerts in there. - if (m_alert_pointer_pos >= m_alert_pointers.size()) + if (m_alert_pointer_pos >= int(m_alert_pointers.size())) { pop_alerts(&m_alert_pointers); m_alert_pointer_pos = 0; @@ -6287,7 +6287,7 @@ namespace aux { alert const* session_impl::pop_alert() { - if (m_alert_pointer_pos >= m_alert_pointers.size()) + if (m_alert_pointer_pos >= int(m_alert_pointers.size())) { pop_alerts(); if (m_alert_pointers.empty()) @@ -6701,8 +6701,8 @@ namespace aux { #if defined TORRENT_EXPENSIVE_INVARIANT_CHECKS TORRENT_ASSERT(int(unique.size()) == total_downloaders); #endif - TORRENT_ASSERT(num_active_downloading == m_torrent_lists[torrent_want_peers_download].size()); - TORRENT_ASSERT(num_active_finished == m_torrent_lists[torrent_want_peers_finished].size()); + TORRENT_ASSERT(num_active_downloading == int(m_torrent_lists[torrent_want_peers_download].size())); + TORRENT_ASSERT(num_active_finished == int(m_torrent_lists[torrent_want_peers_finished].size())); std::unordered_set unique_peers; TORRENT_ASSERT(m_settings.get_int(settings_pack::connections_limit) > 0); diff --git a/src/torrent.cpp b/src/torrent.cpp index 4f4cd57a8..1c8e7f451 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -3551,7 +3551,7 @@ namespace libtorrent #if TORRENT_USE_ASSERTS for (auto j = std::next(i); j != dl_queue.end(); ++j) { - TORRENT_ASSERT(j->index != index); + TORRENT_ASSERT(int(j->index) != index); } #endif @@ -5046,7 +5046,7 @@ namespace libtorrent // pad files always have priority 0 if (fs.pad_file_at(i)) file_prio = 0; - else if (m_file_priority.size() <= i) + else if (int(m_file_priority.size()) <= i) file_prio = 4; else file_prio = m_file_priority[i]; @@ -6242,8 +6242,8 @@ namespace libtorrent if (m_seed_mode) { - TORRENT_ASSERT(m_verified.size() == pieces.size()); - TORRENT_ASSERT(m_verifying.size() == pieces.size()); + TORRENT_ASSERT(m_verified.size() == int(pieces.size())); + TORRENT_ASSERT(m_verifying.size() == int(pieces.size())); for (int i = 0, end(int(pieces.size())); i < end; ++i) pieces[i] |= m_verified[i] ? 2 : 0; } @@ -6509,7 +6509,7 @@ namespace libtorrent if (bi.state == block_info::requested) { auto pbp = peer->downloading_piece_progress(); - if (pbp.piece_index == i->index && pbp.block_index == j) + if (pbp.piece_index == int(i->index) && pbp.block_index == j) { bi.bytes_progress = pbp.bytes_downloaded; TORRENT_ASSERT(bi.bytes_progress <= bi.block_size); @@ -10426,7 +10426,7 @@ namespace libtorrent { peer_connection* peer = static_cast(p->connection); auto pbp = peer->downloading_piece_progress(); - if (pbp.piece_index == i->index && pbp.block_index == k) + if (pbp.piece_index == int(i->index) && pbp.block_index == k) block = pbp.bytes_downloaded; TORRENT_ASSERT(block <= block_size()); } diff --git a/src/torrent_peer_allocator.cpp b/src/torrent_peer_allocator.cpp index f282bb517..77a64a677 100644 --- a/src/torrent_peer_allocator.cpp +++ b/src/torrent_peer_allocator.cpp @@ -101,8 +101,8 @@ namespace libtorrent TORRENT_ASSERT(m_ipv6_peer_pool.is_from(static_cast(p))); static_cast(p)->~ipv6_peer(); m_ipv6_peer_pool.free(p); - TORRENT_ASSERT(m_live_bytes >= sizeof(ipv6_peer)); - m_live_bytes -= sizeof(ipv6_peer); + TORRENT_ASSERT(m_live_bytes >= int(sizeof(ipv6_peer))); + m_live_bytes -= int(sizeof(ipv6_peer)); TORRENT_ASSERT(m_live_allocations > 0); --m_live_allocations; return; @@ -114,8 +114,8 @@ namespace libtorrent TORRENT_ASSERT(m_i2p_peer_pool.is_from(static_cast(p))); static_cast(p)->~i2p_peer(); m_i2p_peer_pool.free(p); - TORRENT_ASSERT(m_live_bytes >= sizeof(i2p_peer)); - m_live_bytes -= sizeof(i2p_peer); + TORRENT_ASSERT(m_live_bytes >= int(sizeof(i2p_peer))); + m_live_bytes -= int(sizeof(i2p_peer)); TORRENT_ASSERT(m_live_allocations > 0); --m_live_allocations; return; @@ -124,11 +124,10 @@ namespace libtorrent TORRENT_ASSERT(m_ipv4_peer_pool.is_from(static_cast(p))); static_cast(p)->~ipv4_peer(); m_ipv4_peer_pool.free(p); - TORRENT_ASSERT(m_live_bytes >= sizeof(ipv4_peer)); - m_live_bytes -= sizeof(ipv4_peer); + TORRENT_ASSERT(m_live_bytes >= int(sizeof(ipv4_peer))); + m_live_bytes -= int(sizeof(ipv4_peer)); TORRENT_ASSERT(m_live_allocations > 0); --m_live_allocations; } } - diff --git a/src/utf8.cpp b/src/utf8.cpp index 9254570a2..36c81b44d 100644 --- a/src/utf8.cpp +++ b/src/utf8.cpp @@ -197,7 +197,7 @@ namespace libtorrent }; TORRENT_ASSERT(ev >= 0); - TORRENT_ASSERT(ev < sizeof(error_messages)/sizeof(error_messages[0])); + TORRENT_ASSERT(ev < int(sizeof(error_messages)/sizeof(error_messages[0]))); return error_messages[ev]; } diff --git a/src/utp_stream.cpp b/src/utp_stream.cpp index 24581ae79..19b56b788 100644 --- a/src/utp_stream.cpp +++ b/src/utp_stream.cpp @@ -976,7 +976,7 @@ void utp_stream::add_write_buffer(void const* buf, size_t len) for (std::vector::iterator i = m_impl->m_write_buffer.begin() , end(m_impl->m_write_buffer.end()); i != end; ++i) { - TORRENT_ASSERT(std::numeric_limits::max() - i->len > write_buffer_size); + TORRENT_ASSERT(std::numeric_limits::max() - int(i->len) > write_buffer_size); write_buffer_size += int(i->len); } TORRENT_ASSERT(m_impl->m_write_buffer_size == write_buffer_size); @@ -990,7 +990,7 @@ void utp_stream::add_write_buffer(void const* buf, size_t len) for (std::vector::iterator i = m_impl->m_write_buffer.begin() , end(m_impl->m_write_buffer.end()); i != end; ++i) { - TORRENT_ASSERT(std::numeric_limits::max() - i->len > write_buffer_size); + TORRENT_ASSERT(std::numeric_limits::max() - int(i->len) > write_buffer_size); write_buffer_size += int(i->len); } TORRENT_ASSERT(m_impl->m_write_buffer_size == write_buffer_size); @@ -1581,7 +1581,7 @@ void utp_socket_impl::write_payload(std::uint8_t* ptr, int size) for (std::vector::iterator i = m_write_buffer.begin() , end(m_write_buffer.end()); i != end; ++i) { - TORRENT_ASSERT(std::numeric_limits::max() - i->len > write_buffer_size); + TORRENT_ASSERT(std::numeric_limits::max() - int(i->len) > write_buffer_size); write_buffer_size += int(i->len); } TORRENT_ASSERT(m_write_buffer_size == write_buffer_size); @@ -1620,7 +1620,7 @@ void utp_socket_impl::write_payload(std::uint8_t* ptr, int size) for (std::vector::iterator j = m_write_buffer.begin() , end(m_write_buffer.end()); j != end; ++j) { - TORRENT_ASSERT(std::numeric_limits::max() - j->len > write_buffer_size); + TORRENT_ASSERT(std::numeric_limits::max() - int(j->len) > write_buffer_size); write_buffer_size += int(j->len); } TORRENT_ASSERT(m_write_buffer_size == write_buffer_size);