From 3f878011426630d64a775a5eb9cb43520027982e Mon Sep 17 00:00:00 2001 From: arvidn Date: Mon, 26 Nov 2018 18:42:20 +0100 Subject: [PATCH] fix some cppcheck warnings --- include/libtorrent/socks5_stream.hpp | 2 +- src/create_torrent.cpp | 12 ++++++------ src/enum_net.cpp | 2 +- src/http_connection.cpp | 2 +- src/identify_client.cpp | 4 +--- src/kademlia/msg.cpp | 2 +- src/kademlia/node.cpp | 5 ++--- src/peer_connection.cpp | 4 ++-- src/peer_list.cpp | 4 ---- src/piece_picker.cpp | 4 ++-- src/udp_tracker_connection.cpp | 6 +++--- 11 files changed, 20 insertions(+), 27 deletions(-) diff --git a/include/libtorrent/socks5_stream.hpp b/include/libtorrent/socks5_stream.hpp index f3e696b87..941a3401b 100644 --- a/include/libtorrent/socks5_stream.hpp +++ b/include/libtorrent/socks5_stream.hpp @@ -114,7 +114,7 @@ public: // if this assert trips, set_dst_name() is called wth an IP address rather // than a hostname. Instead, resolve the IP into an address and pass it to // async_connect instead - TORRENT_ASSERT(!is_ip_address(host.c_str())); + TORRENT_ASSERT(!is_ip_address(host)); m_dst_name = host; if (m_dst_name.size() > 255) m_dst_name.resize(255); diff --git a/src/create_torrent.cpp b/src/create_torrent.cpp index 740df7fc6..23ac38f33 100644 --- a/src/create_torrent.cpp +++ b/src/create_torrent.cpp @@ -393,8 +393,8 @@ namespace { alignment = piece_size; // make sure the size is an even power of 2 -#ifndef NDEBUG - for (int i = 0; i < 32; ++i) +#if TORRENT_USE_ASSERTS + for (int i = 0; i < 31; ++i) { if (piece_size & (1 << i)) { @@ -593,7 +593,7 @@ namespace { { entry& sympath_e = info["symlink path"]; - std::string split = split_path(m_files.symlink(first)); + std::string const split = split_path(m_files.symlink(first)); for (char const* e = split.c_str(); e != nullptr; e = next_path_element(e)) sympath_e.list().emplace_back(e); } @@ -614,12 +614,12 @@ namespace { entry& file_e = files.list().back(); if (m_include_mtime && m_files.mtime(i)) file_e["mtime"] = m_files.mtime(i); file_e["length"] = m_files.file_size(i); - entry& path_e = file_e["path"]; TORRENT_ASSERT(has_parent_path(m_files.file_path(i))); { - std::string split = split_path(m_files.file_path(i)); + entry& path_e = file_e["path"]; + std::string const split = split_path(m_files.file_path(i)); TORRENT_ASSERT(split.c_str() == m_files.name()); for (char const* e = next_path_element(split.c_str()); @@ -642,7 +642,7 @@ namespace { { entry& sympath_e = file_e["symlink path"]; - std::string split = split_path(m_files.symlink(i)); + std::string const split = split_path(m_files.symlink(i)); for (char const* e = split.c_str(); e != nullptr; e = next_path_element(e)) sympath_e.list().emplace_back(e); } diff --git a/src/enum_net.cpp b/src/enum_net.cpp index 8090f8b5a..9250f8b08 100644 --- a/src/enum_net.cpp +++ b/src/enum_net.cpp @@ -990,7 +990,7 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl return std::vector(); } - if (needed <= 0) + if (needed == 0) { return std::vector(); } diff --git a/src/http_connection.cpp b/src/http_connection.cpp index c406571a1..3ae0a2493 100644 --- a/src/http_connection.cpp +++ b/src/http_connection.cpp @@ -295,7 +295,7 @@ void http_connection::start(std::string const& hostname, int port m_read_timeout *= 4; #if TORRENT_USE_I2P - if (is_i2p && i2p_conn->proxy().type != settings_pack::i2p_proxy) + if (i2p_conn->proxy().type != settings_pack::i2p_proxy) { m_timer.get_io_service().post(std::bind(&http_connection::callback , me, error_code(errors::no_i2p_router), span{})); diff --git a/src/identify_client.cpp b/src/identify_client.cpp index eedb2a2a6..6bae0a065 100644 --- a/src/identify_client.cpp +++ b/src/identify_client.cpp @@ -359,9 +359,7 @@ namespace libtorrent { if (f) return f; // look for mainline style id - f = parse_mainline_style(p); - if (f) return f; - return f; + return parse_mainline_style(p); } #endif diff --git a/src/kademlia/msg.cpp b/src/kademlia/msg.cpp index 32fd6e87c..a05754180 100644 --- a/src/kademlia/msg.cpp +++ b/src/kademlia/msg.cpp @@ -84,7 +84,7 @@ bool verify_message_impl(bdecode_node const& message, span des && ret[i] && k.type == bdecode_node::string_t) { - bool const invalid = k.flags & key_desc_t::size_divisible + bool const invalid = (k.flags & key_desc_t::size_divisible) ? (ret[i].string_length() % k.size) != 0 : ret[i].string_length() != k.size; diff --git a/src/kademlia/node.cpp b/src/kademlia/node.cpp index 2592a9f4e..6097542ac 100644 --- a/src/kademlia/node.cpp +++ b/src/kademlia/node.cpp @@ -451,7 +451,7 @@ void node::announce(sha1_hash const& info_hash, int listen_port, announce_flags_ if (listen_port == 0 && m_observer != nullptr) { 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 , m_sock); } @@ -687,7 +687,6 @@ void node::send_single_refresh(udp::endpoint const& ep, int const bucket #endif entry e; e["y"] = "q"; - entry& a = e["a"]; if (m_table.is_full(bucket)) { @@ -700,7 +699,7 @@ void node::send_single_refresh(udp::endpoint const& ep, int const bucket // use get_peers instead of find_node. We'll get nodes in the response // either way. e["q"] = "get_peers"; - a["info_hash"] = target.to_string(); + e["a"]["info_hash"] = target.to_string(); m_counters.inc_stats_counter(counters::dht_get_peers_out); } diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 64286d0d4..0511b9c3d 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -2312,8 +2312,8 @@ namespace libtorrent { { if (e->on_request(r)) return; } -#endif if (is_disconnecting()) return; +#endif if (!t->valid_metadata()) { @@ -5309,7 +5309,7 @@ namespace libtorrent { , "piece: %d s: %x l: %x b: %p c: %s e: %s rtt: %d us" , static_cast(r.piece), r.start, r.length , static_cast(buffer.get()) - , (flags & disk_interface::cache_hit ? "cache hit" : "cache miss") + , ((flags & disk_interface::cache_hit) ? "cache hit" : "cache miss") , error.ec.message().c_str(), disk_rtt); } #endif diff --git a/src/peer_list.cpp b/src/peer_list.cpp index e8f7074a7..a38b35b42 100644 --- a/src/peer_list.cpp +++ b/src/peer_list.cpp @@ -1266,8 +1266,6 @@ namespace libtorrent { TORRENT_ASSERT(m_num_connect_candidates <= int(m_peers.size())); #ifdef TORRENT_EXPENSIVE_INVARIANT_CHECKS - int total_connections = 0; - int nonempty_connections = 0; int connect_candidates = 0; const_iterator prev = m_peers.end(); @@ -1282,7 +1280,6 @@ namespace libtorrent { torrent_peer const& p = **i; TORRENT_ASSERT(p.in_use); if (is_connect_candidate(p)) ++connect_candidates; - ++total_connections; if (!p.connection) { continue; @@ -1294,7 +1291,6 @@ namespace libtorrent { } TORRENT_ASSERT(p.connection->peer_info_struct() == nullptr || p.connection->peer_info_struct() == &p); - ++nonempty_connections; } TORRENT_ASSERT(m_num_connect_candidates == connect_candidates); diff --git a/src/piece_picker.cpp b/src/piece_picker.cpp index c40ad0a00..67d4bd143 100644 --- a/src/piece_picker.cpp +++ b/src/piece_picker.cpp @@ -1265,7 +1265,6 @@ namespace libtorrent { // the piece list dirty, just update those pieces // instead TORRENT_ALLOCA(incremented, piece_index_t, size); - int num_inc = 0; if (!m_dirty) { @@ -1275,6 +1274,7 @@ namespace libtorrent { // this only matters if we're not already dirty, in which case the fasted // thing to do is to just update the counters and be done piece_index_t index = piece_index_t(0); + int num_inc = 0; for (auto i = bitmask.begin(), end(bitmask.end()); i != end; ++i, ++index) { if (!*i) continue; @@ -1361,7 +1361,6 @@ namespace libtorrent { // the piece list dirty, just update those pieces // instead TORRENT_ALLOCA(decremented, piece_index_t, size); - int num_dec = 0; if (!m_dirty) { @@ -1371,6 +1370,7 @@ namespace libtorrent { // this only matters if we're not already dirty, in which case the fasted // thing to do is to just update the counters and be done piece_index_t index = piece_index_t(0); + int num_dec = 0; for (auto i = bitmask.begin(), end(bitmask.end()); i != end; ++i, ++index) { if (!*i) continue; diff --git a/src/udp_tracker_connection.cpp b/src/udp_tracker_connection.cpp index 42713172d..2b9ce9ed5 100644 --- a/src/udp_tracker_connection.cpp +++ b/src/udp_tracker_connection.cpp @@ -267,10 +267,10 @@ namespace libtorrent { // use if if it hasn't expired if (aux::time_now() < cc->second.expires) { - if (0 == (tracker_req().kind & tracker_request::scrape_request)) - send_udp_announce(); - else if (0 != (tracker_req().kind & tracker_request::scrape_request)) + if (tracker_req().kind & tracker_request::scrape_request) send_udp_scrape(); + else + send_udp_announce(); return; } // if it expired, remove it from the cache