From b33dee0f3a04975105ead7fb6c91630da4edddb0 Mon Sep 17 00:00:00 2001 From: arvidn Date: Sun, 18 Feb 2024 15:31:32 +0100 Subject: [PATCH 01/12] use span for bandwidth channels --- include/libtorrent/aux_/bandwidth_manager.hpp | 3 ++- src/bandwidth_manager.cpp | 10 +++++----- src/peer_connection.cpp | 8 ++++---- test/test_bandwidth_limiter.cpp | 7 ++++--- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/include/libtorrent/aux_/bandwidth_manager.hpp b/include/libtorrent/aux_/bandwidth_manager.hpp index c9a42d1851e..ef055ecf4a2 100644 --- a/include/libtorrent/aux_/bandwidth_manager.hpp +++ b/include/libtorrent/aux_/bandwidth_manager.hpp @@ -20,6 +20,7 @@ see LICENSE file. #include "libtorrent/aux_/bandwidth_queue_entry.hpp" #include "libtorrent/aux_/bandwidth_socket.hpp" #include "libtorrent/time.hpp" +#include "libtorrent/span.hpp" namespace libtorrent { namespace aux { @@ -43,7 +44,7 @@ struct TORRENT_EXTRA_EXPORT bandwidth_manager // returns the number of bytes to assign to the peer, or 0 // if the peer's 'assign_bandwidth' callback will be called later int request_bandwidth(std::shared_ptr peer - , int blk, int priority, bandwidth_channel** chan, int num_channels); + , int blk, int priority, span channels); #if TORRENT_USE_INVARIANT_CHECKS void check_invariant() const; diff --git a/src/bandwidth_manager.cpp b/src/bandwidth_manager.cpp index edf81c74a00..7a0748babe1 100644 --- a/src/bandwidth_manager.cpp +++ b/src/bandwidth_manager.cpp @@ -65,7 +65,7 @@ namespace libtorrent::aux { // others will cut in front of the non-prioritized peers. // this is used by web seeds int bandwidth_manager::request_bandwidth(std::shared_ptr peer - , int const blk, int const priority, bandwidth_channel** chan, int const num_channels) + , int const blk, int const priority, span channels) { INVARIANT_CHECK; if (m_abort) return 0; @@ -77,7 +77,7 @@ namespace libtorrent::aux { // being assigned bandwidth for an already outstanding request TORRENT_ASSERT(!is_queued(peer.get())); - if (num_channels == 0) + if (channels.empty()) { // the connection is not rate limited by any of its // bandwidth channels, or it doesn't belong to any @@ -88,10 +88,10 @@ namespace libtorrent::aux { int k = 0; bw_request bwr(std::move(peer), blk, priority); - for (int i = 0; i < num_channels; ++i) + for (auto const& c : channels) { - if (chan[i]->need_queueing(blk)) - bwr.channel[k++] = chan[i]; + if (c->need_queueing(blk)) + bwr.channel[k++] = c; } if (k == 0) return blk; diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 01167f856a6..122f1d6484c 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -5708,10 +5708,10 @@ namespace { #if TORRENT_USE_ASSERTS // make sure we don't have duplicates std::set unique_classes; - for (int i = 0; i < c; ++i) + for (auto chan : channels.first(c)) { - TORRENT_ASSERT(unique_classes.count(channels[i]) == 0); - unique_classes.insert(channels[i]); + TORRENT_ASSERT(unique_classes.count(chan) == 0); + unique_classes.insert(chan); } #endif @@ -5720,7 +5720,7 @@ namespace { aux::bandwidth_manager* manager = m_ses.get_bandwidth_manager(channel); int const ret = manager->request_bandwidth(self() - , bytes, priority, channels.data(), c); + , bytes, priority, channels.first(c)); if (ret == 0) { diff --git a/test/test_bandwidth_limiter.cpp b/test/test_bandwidth_limiter.cpp index 85d4134c490..f82c16a692e 100644 --- a/test/test_bandwidth_limiter.cpp +++ b/test/test_bandwidth_limiter.cpp @@ -19,6 +19,7 @@ see LICENSE file. #include "libtorrent/aux_/stat.hpp" #include "libtorrent/time.hpp" #include "libtorrent/aux_/session_settings.hpp" +#include "libtorrent/aux_/array.hpp" #include #include @@ -82,13 +83,13 @@ void peer_connection::assign_bandwidth(int /*channel*/, int amount) void peer_connection::start() { - aux::bandwidth_channel* channels[] = { + aux::array channels{{ &m_bandwidth_channel , &m_torrent_bandwidth_channel , &global_bwc - }; + }}; - m_bwm.request_bandwidth(shared_from_this(), 400000000, m_priority, channels, 3); + m_bwm.request_bandwidth(shared_from_this(), 400000000, m_priority, channels); } From a4b4e5ee6383ec9d62b55c33618b56c233b8190f Mon Sep 17 00:00:00 2001 From: arvidn Date: Sun, 18 Feb 2024 15:37:56 +0100 Subject: [PATCH 02/12] use std::array in peer_class --- include/libtorrent/peer_class.hpp | 3 ++- src/peer_connection.cpp | 4 ++-- src/torrent.cpp | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/libtorrent/peer_class.hpp b/include/libtorrent/peer_class.hpp index 86fd26359e1..1915c80979a 100644 --- a/include/libtorrent/peer_class.hpp +++ b/include/libtorrent/peer_class.hpp @@ -18,6 +18,7 @@ see LICENSE file. #include "libtorrent/aux_/deque.hpp" #include +#include #include #include #include @@ -102,7 +103,7 @@ namespace libtorrent { // priority for bandwidth allocation // in rate limiter. One for upload and one // for download - int priority[2]; + std::array priority; // the name of this peer class std::string label; diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 122f1d6484c..9e4742f355d 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -253,7 +253,7 @@ namespace { int prio = 1; for (int i = 0; i < num_classes(); ++i) { - int class_prio = m_ses.peer_classes().at(class_at(i))->priority[channel]; + int class_prio = m_ses.peer_classes().at(class_at(i))->priority[std::size_t(channel)]; if (prio < class_prio) prio = class_prio; } @@ -263,7 +263,7 @@ namespace { { for (int i = 0; i < t->num_classes(); ++i) { - int class_prio = m_ses.peer_classes().at(t->class_at(i))->priority[channel]; + int class_prio = m_ses.peer_classes().at(t->class_at(i))->priority[std::size_t(channel)]; if (prio < class_prio) prio = class_prio; } } diff --git a/src/torrent.cpp b/src/torrent.cpp index 5367b2ec448..d19bf9bcc98 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -12090,7 +12090,7 @@ namespace { int priority = 0; for (int i = 0; i < num_classes(); ++i) { - int const* prio = m_ses.peer_classes().at(class_at(i))->priority; + span prio = m_ses.peer_classes().at(class_at(i))->priority; priority = std::max(priority, prio[peer_connection::upload_channel]); priority = std::max(priority, prio[peer_connection::download_channel]); } From c38a9f07101993dbd5aa9ccdc080f570e8f17ed0 Mon Sep 17 00:00:00 2001 From: arvidn Date: Sun, 18 Feb 2024 15:43:13 +0100 Subject: [PATCH 03/12] use array in i2p_stream --- src/i2p_stream.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/i2p_stream.cpp b/src/i2p_stream.cpp index 0117bfec4f2..d4572b85cdd 100644 --- a/src/i2p_stream.cpp +++ b/src/i2p_stream.cpp @@ -19,6 +19,7 @@ see LICENSE file. #include "libtorrent/assert.hpp" #include "libtorrent/error_code.hpp" #include "libtorrent/settings_pack.hpp" +#include "libtorrent/aux_/array.hpp" namespace libtorrent { @@ -28,7 +29,7 @@ namespace libtorrent { { return "i2p error"; } std::string message(int ev) const override { - static char const* messages[] = + static aux::array messages{ { "no error", "parse failed", @@ -39,7 +40,7 @@ namespace libtorrent { "timeout", "key not found", "duplicated id" - }; + }}; if (ev < 0 || ev >= i2p_error::num_errors) return "unknown error"; return messages[ev]; From af7f100384096033b5b4dec51ba73bf6d2e53946 Mon Sep 17 00:00:00 2001 From: arvidn Date: Sun, 18 Feb 2024 16:34:39 +0100 Subject: [PATCH 04/12] use array got m_channel_state --- include/libtorrent/aux_/peer_connection.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/libtorrent/aux_/peer_connection.hpp b/include/libtorrent/aux_/peer_connection.hpp index 93244c0d888..f4f8777b0b5 100644 --- a/include/libtorrent/aux_/peer_connection.hpp +++ b/include/libtorrent/aux_/peer_connection.hpp @@ -808,7 +808,7 @@ namespace libtorrent::aux { public: // upload and download channel state // enum from peer_info::bw_state - bandwidth_state_flags_t m_channel_state[2]; + aux::array m_channel_state; protected: aux::receive_buffer m_recv_buffer; From 26d1086886d14124ba1e18797d597c4d6a8c011f Mon Sep 17 00:00:00 2001 From: arvidn Date: Sun, 18 Feb 2024 16:49:34 +0100 Subject: [PATCH 05/12] use array in gzip --- src/gzip.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/gzip.cpp b/src/gzip.cpp index dbb5963dc62..1c4068e7f8b 100644 --- a/src/gzip.cpp +++ b/src/gzip.cpp @@ -11,6 +11,7 @@ see LICENSE file. #include "libtorrent/assert.hpp" #include "libtorrent/aux_/puff.hpp" #include "libtorrent/gzip.hpp" +#include "libtorrent/aux_/array.hpp" #include @@ -48,7 +49,7 @@ namespace libtorrent { std::string gzip_error_category::message(int ev) const { - static char const* msgs[] = + static aux::array msgs{ { "no error", "invalid gzip header", @@ -66,8 +67,8 @@ namespace libtorrent { "invalid literal/length or distance code in fixed or dynamic block", "distance is too far back in fixed or dynamic block", "unknown gzip error", - }; - if (ev < 0 || ev >= int(sizeof(msgs)/sizeof(msgs[0]))) + }}; + if (ev < 0 || ev >= msgs.end_index()) return "Unknown error"; return msgs[ev]; } From 7b489e70891fdf523e62b5db6417dc8c144817f4 Mon Sep 17 00:00:00 2001 From: arvidn Date: Sun, 18 Feb 2024 16:51:48 +0100 Subject: [PATCH 06/12] use array for alert messages --- src/alert.cpp | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/alert.cpp b/src/alert.cpp index 5fc4bc74082..1faaa978ae3 100644 --- a/src/alert.cpp +++ b/src/alert.cpp @@ -281,7 +281,7 @@ namespace libtorrent { TORRENT_UNUSED(i); return ""; #else - static char const* const warning_str[] = + static aux::array const warning_str{ { "max outstanding disk writes reached", "max outstanding piece requests reached", @@ -294,10 +294,10 @@ namespace libtorrent { "", "too few ports allowed for outgoing connections", "too few file descriptors are allowed for this process. connection limit lowered" - }; + }}; TORRENT_ASSERT(i >= 0); - TORRENT_ASSERT(i < std::end(warning_str) - std::begin(warning_str)); + TORRENT_ASSERT(i < warning_str.end_index()); return warning_str[i]; #endif } @@ -1370,8 +1370,7 @@ namespace { return {}; #else char ret[600]; - static char const* const reason_str[] = - { + static aux::array const reason_str{{ "ip_filter", "port_filter", "i2p_mixed", @@ -1380,7 +1379,7 @@ namespace { "tcp_disabled", "invalid_local_interface", "ssrf_mitigation" - }; + }}; std::snprintf(ret, sizeof(ret), "%s: blocked peer [%s]" , peer_alert::message().c_str(), reason_str[reason]); @@ -1508,9 +1507,9 @@ namespace { return {}; #else char msg[200]; - static char const* const msgs[] = { + static aux::array const msgs{{ "tracker is not anonymous, set a proxy" - }; + }}; std::snprintf(msg, sizeof(msg), "%s: %s: %s" , torrent_alert::message().c_str() , msgs[kind], str.c_str()); @@ -2156,8 +2155,8 @@ namespace { #ifdef TORRENT_DISABLE_ALERT_MSG return {}; #else - static char const* const mode[] = - { "<==", "==>", "<<<", ">>>", "***" }; + static aux::array const mode{ + { "<==", "==>", "<<<", ">>>", "***" }}; return peer_alert::message() + " [" + print_endpoint(endpoint) + "] " + mode[direction] + " " + event_type + " [ " + log_message() + " ]"; #endif @@ -2385,14 +2384,13 @@ namespace { #ifdef TORRENT_DISABLE_ALERT_MSG return {}; #else - static char const* const dht_modules[] = - { + static aux::array const dht_modules{{ "tracker", "node", "routing_table", "rpc_manager", "traversal" - }; + }}; char ret[900]; std::snprintf(ret, sizeof(ret), "DHT %s: %s", dht_modules[module] @@ -2434,7 +2432,7 @@ namespace { std::string msg = print_entry(print, true); - static char const* const prefix[2] = {"<==", "==>"}; + static aux::array const prefix{{"<==", "==>"}}; char buf[1024]; std::snprintf(buf, sizeof(buf), "%s [%s] %s", prefix[direction] , print_endpoint(node).c_str(), msg.c_str()); @@ -2589,8 +2587,7 @@ namespace { #ifdef TORRENT_DISABLE_ALERT_MSG return {}; #else - static char const* const flag_names[] = - { + static aux::array const flag_names{{ "partial_ratio ", "prioritize_partials ", "rarest_first_partials ", @@ -2608,7 +2605,7 @@ namespace { "backup2 ", "end_game ", "extent_affinity ", - }; + }}; std::string ret = peer_alert::message(); From 50592c2f3072426b1f774ad26aa3088b5f22c91f Mon Sep 17 00:00:00 2001 From: arvidn Date: Sun, 18 Feb 2024 16:52:38 +0100 Subject: [PATCH 07/12] use array for error messages --- src/error_code.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/error_code.cpp b/src/error_code.cpp index a1687763334..7b884e57ffd 100644 --- a/src/error_code.cpp +++ b/src/error_code.cpp @@ -13,6 +13,7 @@ see LICENSE file. #include "libtorrent/config.hpp" #include "libtorrent/error_code.hpp" #include "libtorrent/aux_/string_util.hpp" // for to_string() +#include "libtorrent/aux_/array.hpp" #include @@ -33,7 +34,7 @@ namespace libtorrent { std::string libtorrent_error_category::message(int ev) const { - static char const* msgs[] = + static aux::array msgs{ { "no error", "torrent file collides with file from another torrent", @@ -272,8 +273,8 @@ namespace libtorrent { "a v2 file entry has no root hash", "v1 and v2 hashes do not describe the same data", "a file in the v2 metadata has the pad attribute set" - }; - if (ev < 0 || ev >= int(sizeof(msgs)/sizeof(msgs[0]))) + }}; + if (ev < 0 || ev >= msgs.end_index()) return "Unknown error"; return msgs[ev]; } From 52adf548444a25fa7b5e7943e564b78d027c9fd4 Mon Sep 17 00:00:00 2001 From: arvidn Date: Sun, 18 Feb 2024 16:53:38 +0100 Subject: [PATCH 08/12] use array in escape_string --- src/escape_string.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/escape_string.cpp b/src/escape_string.cpp index a8c00c9fc16..93b52b9a2d9 100644 --- a/src/escape_string.cpp +++ b/src/escape_string.cpp @@ -39,7 +39,7 @@ namespace libtorrent { // defined in hex.cpp namespace aux { - extern const char hex_chars[]; + extern const aux::array hex_chars; } std::string unescape_string(string_view s, error_code& ec) @@ -223,7 +223,7 @@ namespace libtorrent { std::string base64encode(const std::string& s) { - static char const base64_table[] = + static aux::array const base64_table{ { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', @@ -233,7 +233,7 @@ namespace libtorrent { 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' - }; + }}; aux::array inbuf; aux::array outbuf; @@ -331,13 +331,13 @@ namespace { std::string base32encode_i2p(span s) { - static char const base32_table[] = + static aux::array const base32_table{ { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '2', '3', '4', '5', '6', '7' - }; + }}; static aux::array const input_output_mapping{{{0, 2, 4, 5, 7, 8}}}; From 8f8deccf8d00f7d7e7973eaba4885f44591f658a Mon Sep 17 00:00:00 2001 From: arvidn Date: Sun, 18 Feb 2024 16:54:28 +0100 Subject: [PATCH 09/12] use array in hex.cpp --- src/hex.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/hex.cpp b/src/hex.cpp index d9a3b3db8d8..370807c1204 100644 --- a/src/hex.cpp +++ b/src/hex.cpp @@ -10,6 +10,7 @@ see LICENSE file. */ #include "libtorrent/hex.hpp" +#include "libtorrent/aux_/array.hpp" namespace libtorrent { @@ -48,9 +49,12 @@ namespace libtorrent { return true; } - extern char const hex_chars[]; + extern aux::array const hex_chars; - char const hex_chars[] = "0123456789abcdef"; + aux::array const hex_chars{{ + '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' + }}; void to_hex(char const* in, int const len, char* out) { int idx = 0; From 324234142505c0d308cf23a834c0654834eb3f00 Mon Sep 17 00:00:00 2001 From: arvidn Date: Sun, 18 Feb 2024 16:55:24 +0100 Subject: [PATCH 10/12] use array in test framework --- test/test.cpp | 3 ++- test/test.hpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/test/test.cpp b/test/test.cpp index 09972449343..eee75698fda 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -9,12 +9,13 @@ see LICENSE file. */ #include +#include "libtorrent/aux_/array.hpp" #include "test.hpp" namespace unit_test { -unit_test_t g_unit_tests[1024]; +lt::aux::array g_unit_tests; int g_num_unit_tests = 0; int g_test_failures = 0; // flushed at start of every unit int g_test_idx = 0; diff --git a/test/test.hpp b/test/test.hpp index e5b353e7a2d..8653c469581 100644 --- a/test/test.hpp +++ b/test/test.hpp @@ -13,6 +13,7 @@ see LICENSE file. #include "libtorrent/address.hpp" #include "libtorrent/socket.hpp" +#include "libtorrent/aux_/array.hpp" #include #include @@ -57,7 +58,7 @@ struct unit_test_t FILE* output; }; -extern unit_test_t EXPORT g_unit_tests[1024]; +extern lt::aux::array EXPORT g_unit_tests; extern int EXPORT g_num_unit_tests; extern int EXPORT g_test_failures; extern int g_test_idx; From 66ddd8e299aa9e31c4c4fc73d1599f4b980b3098 Mon Sep 17 00:00:00 2001 From: arvidn Date: Sun, 18 Feb 2024 16:56:27 +0100 Subject: [PATCH 11/12] use array in stat.hpp --- include/libtorrent/aux_/stat.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/libtorrent/aux_/stat.hpp b/include/libtorrent/aux_/stat.hpp index 071d6ee398b..39be9c9b9ff 100644 --- a/include/libtorrent/aux_/stat.hpp +++ b/include/libtorrent/aux_/stat.hpp @@ -18,6 +18,7 @@ see LICENSE file. #include "libtorrent/config.hpp" #include "libtorrent/assert.hpp" +#include "libtorrent/aux_/array.hpp" namespace libtorrent::aux { @@ -256,7 +257,7 @@ namespace libtorrent::aux { private: - stat_channel m_stat[num_channels]; + aux::array m_stat; }; } From 1df8ff78e2c2d3d6c79a58a306e3fec114aded7e Mon Sep 17 00:00:00 2001 From: arvidn Date: Thu, 1 Feb 2024 11:24:06 +0100 Subject: [PATCH 12/12] fix warnings in new versions of clang --- .../libtorrent/aux_/heterogeneous_queue.hpp | 11 ++++++++++ include/libtorrent/aux_/netlink_utils.hpp | 2 ++ include/libtorrent/bitfield.hpp | 11 ++++++++++ include/libtorrent/span.hpp | 11 ++++++++++ src/assert.cpp | 22 ++++++++++++++++++- src/bdecode.cpp | 11 ++++++++++ src/bitfield.cpp | 12 ++++++++++ src/cpuid.cpp | 10 +++++++++ src/crc32c.cpp | 10 +++++++++ src/fingerprint.cpp | 11 ++++++++++ src/http_parser.cpp | 11 ++++++++++ src/torrent.cpp | 2 +- 12 files changed, 122 insertions(+), 2 deletions(-) diff --git a/include/libtorrent/aux_/heterogeneous_queue.hpp b/include/libtorrent/aux_/heterogeneous_queue.hpp index 67a9b4bf987..1b0a2b35566 100644 --- a/include/libtorrent/aux_/heterogeneous_queue.hpp +++ b/include/libtorrent/aux_/heterogeneous_queue.hpp @@ -24,6 +24,13 @@ see LICENSE file. #include #endif +#ifdef __clang__ +// disable these warnings until this class is re-worked in a way clang likes +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunknown-warning-option" +#pragma clang diagnostic ignored "-Wunsafe-buffer-usage" +#endif + namespace libtorrent { namespace aux { @@ -274,4 +281,8 @@ namespace aux { }; } // namespace libtorrent +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + #endif diff --git a/include/libtorrent/aux_/netlink_utils.hpp b/include/libtorrent/aux_/netlink_utils.hpp index 190780cb2b7..0b5c3826409 100644 --- a/include/libtorrent/aux_/netlink_utils.hpp +++ b/include/libtorrent/aux_/netlink_utils.hpp @@ -48,6 +48,8 @@ namespace aux { #pragma clang diagnostic ignored "-Wsign-compare" #pragma clang diagnostic ignored "-Wcast-qual" #pragma clang diagnostic ignored "-Wcast-align" +#pragma clang diagnostic ignored "-Wunknown-warning-option" +#pragma clang diagnostic ignored "-Wunsafe-buffer-usage" #endif // these are here to concentrate all the shady casts these macros expand to, // to disable the warnings for them all diff --git a/include/libtorrent/bitfield.hpp b/include/libtorrent/bitfield.hpp index 38743148e37..a6ee6506e49 100644 --- a/include/libtorrent/bitfield.hpp +++ b/include/libtorrent/bitfield.hpp @@ -22,6 +22,13 @@ see LICENSE file. #include // for memset and memcpy #include // uint32_t +#ifdef __clang__ +// disable these warnings until this class is re-worked in a way clang likes +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunknown-warning-option" +#pragma clang diagnostic ignored "-Wunsafe-buffer-usage" +#endif + namespace libtorrent { // The bitfield type stores any number of bits as a bitfield @@ -330,4 +337,8 @@ namespace libtorrent { }; } +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + #endif // TORRENT_BITFIELD_HPP_INCLUDED diff --git a/include/libtorrent/span.hpp b/include/libtorrent/span.hpp index 1c177f8537b..ee1dd244113 100644 --- a/include/libtorrent/span.hpp +++ b/include/libtorrent/span.hpp @@ -42,6 +42,13 @@ namespace aux { }; } +#ifdef __clang__ +// disable these warnings until this class is re-worked in a way clang likes +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunknown-warning-option" +#pragma clang diagnostic ignored "-Wunsafe-buffer-usage" +#endif + template struct span { @@ -153,6 +160,10 @@ namespace aux { difference_type m_len; }; +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + template inline bool operator==(span const& lhs, span const& rhs) { diff --git a/src/assert.cpp b/src/assert.cpp index f50283e2991..f60a4ce13f7 100644 --- a/src/assert.cpp +++ b/src/assert.cpp @@ -45,10 +45,16 @@ see LICENSE file. #include +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunknown-warning-option" +#pragma clang diagnostic ignored "-Wunsafe-buffer-usage" +#endif + namespace libtorrent { std::string demangle(char const* name) { -// in case this string comes + // in case this string comes // this is needed on linux char const* start = std::strchr(name, '('); if (start != nullptr) @@ -83,6 +89,10 @@ std::string demangle(char const* name) ::free(unmangled); return ret; } + +#ifdef __clang__ +#pragma clang diagnostic pop +#endif } #elif defined _WIN32 && !defined TORRENT_WINRT @@ -113,6 +123,12 @@ std::string demangle(char const* name) { return name; } #if TORRENT_USE_EXECINFO #include +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunknown-warning-option" +#pragma clang diagnostic ignored "-Wunsafe-buffer-usage" +#endif + namespace libtorrent { TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth, void*) @@ -133,6 +149,10 @@ TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth, void*) } } +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + #elif defined _WIN32 && !defined TORRENT_WINRT #include "libtorrent/aux_/windows.hpp" diff --git a/src/bdecode.cpp b/src/bdecode.cpp index 66f9cecc44d..83eda3fb003 100644 --- a/src/bdecode.cpp +++ b/src/bdecode.cpp @@ -25,6 +25,13 @@ see LICENSE file. #define BOOST_SYSTEM_NOEXCEPT throw() #endif +#ifdef __clang__ +// disable these warnings until this class is re-worked in a way clang likes +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunknown-warning-option" +#pragma clang diagnostic ignored "-Wunsafe-buffer-usage" +#endif + namespace libtorrent { using aux::bdecode_token; @@ -1160,3 +1167,7 @@ namespace aux { return ret; } } + +#ifdef __clang__ +#pragma clang diagnostic pop +#endif diff --git a/src/bitfield.cpp b/src/bitfield.cpp index 91a57e1e864..a0c0ad3a3d9 100644 --- a/src/bitfield.cpp +++ b/src/bitfield.cpp @@ -17,6 +17,13 @@ see LICENSE file. #include #endif +#ifdef __clang__ +// disable these warnings until this class is re-worked in a way clang likes +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunknown-warning-option" +#pragma clang diagnostic ignored "-Wunsafe-buffer-usage" +#endif + namespace libtorrent { bool bitfield::all_set() const noexcept @@ -225,3 +232,8 @@ namespace libtorrent { static_assert(std::is_nothrow_default_constructible>::value , "should be nothrow default constructible"); } + +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + diff --git a/src/cpuid.cpp b/src/cpuid.cpp index 9ef2d923c6d..ef3fa877858 100644 --- a/src/cpuid.cpp +++ b/src/cpuid.cpp @@ -57,6 +57,12 @@ namespace libtorrent { namespace aux { namespace { +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunknown-warning-option" +#pragma clang diagnostic ignored "-Wunsafe-buffer-usage" +#endif + #if TORRENT_HAS_SSE // internal void cpuid(std::uint32_t* info, int type) noexcept @@ -130,6 +136,10 @@ namespace { #endif } +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + } // anonymous namespace bool const sse42_support = supports_sse42(); diff --git a/src/crc32c.cpp b/src/crc32c.cpp index 91009cf7141..c471d0f1811 100644 --- a/src/crc32c.cpp +++ b/src/crc32c.cpp @@ -26,6 +26,12 @@ see LICENSE file. #include #endif +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunknown-warning-option" +#pragma clang diagnostic ignored "-Wunsafe-buffer-usage" +#endif + namespace libtorrent::aux { std::uint32_t crc32c_32(std::uint32_t v) @@ -126,3 +132,7 @@ namespace libtorrent::aux { return crc.checksum(); } } + +#ifdef __clang__ +#pragma clang diagnostic pop +#endif diff --git a/src/fingerprint.cpp b/src/fingerprint.cpp index 34dfb8b7920..6bc54d86796 100644 --- a/src/fingerprint.cpp +++ b/src/fingerprint.cpp @@ -51,6 +51,13 @@ namespace libtorrent { return ret; } +#ifdef __clang__ +// TODO: the fingerprint constructor should take a string_view +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunknown-warning-option" +#pragma clang diagnostic ignored "-Wunsafe-buffer-usage" +#endif + fingerprint::fingerprint(const char* id_string, int major, int minor , int revision, int tag) : major_version(major) @@ -68,6 +75,10 @@ namespace libtorrent { name[1] = id_string[1]; } +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + #if TORRENT_ABI_VERSION == 1 std::string fingerprint::to_string() const { diff --git a/src/http_parser.cpp b/src/http_parser.cpp index bd018e890ac..be6c3f72a51 100644 --- a/src/http_parser.cpp +++ b/src/http_parser.cpp @@ -25,6 +25,12 @@ see LICENSE file. #include "libtorrent/time.hpp" // for seconds32 #include "libtorrent/aux_/numeric_cast.hpp" +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunknown-warning-option" +#pragma clang diagnostic ignored "-Wunsafe-buffer-usage" +#endif + namespace libtorrent::aux { bool is_ok_status(int http_status) @@ -623,3 +629,8 @@ namespace libtorrent::aux { return buffer.first(write_ptr - buffer.data()); } } + +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + diff --git a/src/torrent.cpp b/src/torrent.cpp index d19bf9bcc98..0208c82bfae 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -10436,7 +10436,7 @@ namespace { int num_peers = 0; int num_downloaders = 0; int missing_pieces = 0; - for (auto* p : m_connections) + for (auto const* const p : m_connections) { TORRENT_INCREMENT(m_iterating_connections); if (p->is_connecting()) continue;