From c5cea1221fe00a4c46696ebe3dfc3846890f3b24 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 17 Jan 2025 13:06:50 -0800 Subject: [PATCH 1/5] clang-tidy: concat some namespaces Found with modernize-concat-nested-namespaces Signed-off-by: Rosen Penev --- src/torrent/utils/uri_parser.cc | 4 ++-- src/torrent/utils/uri_parser.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/torrent/utils/uri_parser.cc b/src/torrent/utils/uri_parser.cc index 811b483fc..a31dd6ffe 100644 --- a/src/torrent/utils/uri_parser.cc +++ b/src/torrent/utils/uri_parser.cc @@ -42,7 +42,7 @@ #include "rak/string_manip.h" -namespace torrent { namespace utils { +namespace torrent::utils { inline bool is_unreserved_uri_char(char c) { @@ -196,4 +196,4 @@ uri_parse_query_str(const char* query, uri_query_state& state) { uri_parse_query_str(std::string(query), state); } -}} +} diff --git a/src/torrent/utils/uri_parser.h b/src/torrent/utils/uri_parser.h index b535d9e79..4fbbaa382 100644 --- a/src/torrent/utils/uri_parser.h +++ b/src/torrent/utils/uri_parser.h @@ -42,7 +42,7 @@ #include #include -namespace torrent { namespace utils { +namespace torrent::utils { typedef std::vector uri_resource_list; typedef std::vector uri_query_list; @@ -91,6 +91,6 @@ class LIBTORRENT_EXPORT uri_error : public ::torrent::input_error { uri_error(const std::string& msg) : ::torrent::input_error(msg) {} }; -}} +} #endif From cc14f97151b1a83ec7ae0e9fcd5f0bc212d54e85 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 17 Jan 2025 13:56:00 -0800 Subject: [PATCH 2/5] clang-tidy: assign in if Found with bugprone-assignment-in-if-condition Signed-off-by: Rosen Penev --- src/torrent/connection_manager.cc | 3 +-- src/torrent/data/block.h | 14 ++++---------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/torrent/connection_manager.cc b/src/torrent/connection_manager.cc index ea5efc589..347de4987 100644 --- a/src/torrent/connection_manager.cc +++ b/src/torrent/connection_manager.cc @@ -57,9 +57,8 @@ resolve_host(const char* host, int family, int socktype, ConnectionManager::slot thread_base::release_global_lock(); rak::address_info* ai; - int err; - if ((err = rak::address_info::get_address_info(host, family, socktype, &ai)) != 0) { + if (int err = rak::address_info::get_address_info(host, family, socktype, &ai); err != 0) { if (manager->main_thread_main()->is_current()) thread_base::acquire_global_lock(); diff --git a/src/torrent/data/block.h b/src/torrent/data/block.h index c6e3d8c9a..76cfee844 100644 --- a/src/torrent/data/block.h +++ b/src/torrent/data/block.h @@ -163,22 +163,16 @@ Block::Block() : inline BlockTransfer* Block::find(const PeerInfo* p) { - BlockTransfer* transfer; - - if ((transfer = find_queued(p)) != NULL) + if (auto transfer = find_queued(p)) return transfer; - else - return find_transfer(p); + return find_transfer(p); } inline const BlockTransfer* Block::find(const PeerInfo* p) const { - const BlockTransfer* transfer; - - if ((transfer = find_queued(p)) != NULL) + if (auto transfer = find_queued(p)) return transfer; - else - return find_transfer(p); + return find_transfer(p); } inline void From f841442210263c7f912ddc6b549b86f572d486b2 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 17 Jan 2025 14:42:43 -0800 Subject: [PATCH 3/5] clang-tidy: remove pointless inline Signed-off-by: Rosen Penev --- src/torrent/object.h | 4 ++-- src/torrent/utils/thread_base.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/torrent/object.h b/src/torrent/object.h index 3f9fe7e40..fda8ef45d 100644 --- a/src/torrent/object.h +++ b/src/torrent/object.h @@ -247,8 +247,8 @@ class LIBTORRENT_EXPORT Object { void swap_same_type(Object& left, Object& right); private: - inline bool check(map_type::const_iterator itr, type_type t) const { return itr != _map().end() && itr->second.type() == t; } - inline void check_throw(type_type t) const { if (t != type()) throw bencode_error("Wrong object type."); } + bool check(map_type::const_iterator itr, type_type t) const { return itr != _map().end() && itr->second.type() == t; } + void check_throw(type_type t) const { if (t != type()) throw bencode_error("Wrong object type."); } template void check_value_throw(const char* err_msg) const; diff --git a/src/torrent/utils/thread_base.h b/src/torrent/utils/thread_base.h index 4f7c77460..ad5b305a0 100644 --- a/src/torrent/utils/thread_base.h +++ b/src/torrent/utils/thread_base.h @@ -71,7 +71,7 @@ class LIBTORRENT_EXPORT thread_base { slot_void& slot_do_work() { return m_slot_do_work; } slot_timer& slot_next_timeout() { return m_slot_next_timeout; } - static inline int global_queue_size() { return m_global.waiting; } + static int global_queue_size() { return m_global.waiting; } static inline void acquire_global_lock(); static inline bool trylock_global_lock(); From 16057c82d401930fd4437a02055711834db616ba Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 17 Jan 2025 14:45:27 -0800 Subject: [PATCH 4/5] clang-tidy: simplify booleans Signed-off-by: Rosen Penev --- src/net/protocol_buffer.h | 5 +---- src/net/socket_listen.cc | 2 +- src/protocol/handshake.cc | 4 ++-- src/torrent/tracker.h | 2 +- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/net/protocol_buffer.h b/src/net/protocol_buffer.h index 1fbe572dd..a2cf0b985 100644 --- a/src/net/protocol_buffer.h +++ b/src/net/protocol_buffer.h @@ -141,10 +141,7 @@ inline bool ProtocolBuffer::consume(difference_type v) { m_position += v; - if (remaining()) - return false; - - return true; + return !static_cast(remaining()); } template diff --git a/src/net/socket_listen.cc b/src/net/socket_listen.cc index 97f006e0c..29db9dd0d 100644 --- a/src/net/socket_listen.cc +++ b/src/net/socket_listen.cc @@ -37,7 +37,7 @@ socket_listen::open(sa_unique_ptr&& sap, uint16_t first_port, uint16_t last_port throw internal_error("socket_listen::open: socket address is inet without v4only flag"); if (first_port == 0 || last_port == 0 || start_port == 0 || - !(first_port <= last_port && first_port <= start_port && start_port <= last_port)) + first_port > last_port || first_port > start_port || start_port > last_port) throw internal_error("socket_listen::open: port range not valid"); int fd = fd_open(open_flags); diff --git a/src/protocol/handshake.cc b/src/protocol/handshake.cc index ae5a4f6c1..9741fb8c4 100644 --- a/src/protocol/handshake.cc +++ b/src/protocol/handshake.cc @@ -638,7 +638,7 @@ Handshake::read_port() { void Handshake::read_done() { - if (m_readDone != false) + if (m_readDone) throw internal_error("Handshake::read_done() m_readDone != false."); // if (m_peerInfo->supports_extensions() && m_extensions->is_initial_handshake()) @@ -1171,7 +1171,7 @@ void Handshake::write_bitfield() { const Bitfield* bitfield = m_download->file_list()->bitfield(); - if (m_writeDone != false) + if (m_writeDone) throw internal_error("Handshake::event_write() m_writeDone != false."); if (m_writeBuffer.remaining()) diff --git a/src/torrent/tracker.h b/src/torrent/tracker.h index e7a249de2..ca2330b17 100644 --- a/src/torrent/tracker.h +++ b/src/torrent/tracker.h @@ -159,7 +159,7 @@ class LIBTORRENT_EXPORT Tracker { inline bool Tracker::can_request_state() const { - return !(is_busy() && latest_event() != EVENT_SCRAPE) && is_usable(); + return (!is_busy() || latest_event() == EVENT_SCRAPE) && is_usable(); } } From 7a28faf567046c188232db8ab9263671c825a79e Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 17 Jan 2025 15:03:34 -0800 Subject: [PATCH 5/5] clang-tidy: add const to pointer param Signed-off-by: Rosen Penev --- src/torrent/download/choke_queue.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/torrent/download/choke_queue.cc b/src/torrent/download/choke_queue.cc index 91c0b7276..d4fcf8471 100644 --- a/src/torrent/download/choke_queue.cc +++ b/src/torrent/download/choke_queue.cc @@ -425,7 +425,7 @@ choke_queue::move_connections(choke_queue* src, choke_queue* dest, DownloadMain* void choke_manager_allocate_slots(choke_queue::iterator first, choke_queue::iterator last, - uint32_t max, uint32_t* weights, choke_queue::target_type* target) { + uint32_t max, const uint32_t* weights, choke_queue::target_type* target) { // Sorting the connections from the lowest to highest value. // TODO: std::sort(first, last, choke_manager_less);