Skip to content

Commit

Permalink
fix warnings in new versions of clang
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidn committed Feb 1, 2024
1 parent 3770d17 commit 2dd665a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 18 deletions.
11 changes: 11 additions & 0 deletions include/libtorrent/aux_/heterogeneous_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ POSSIBILITY OF SUCH DAMAGE.
#include <sanitizer/common_interface_defs.h>
#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 {

Expand Down Expand Up @@ -297,4 +304,8 @@ namespace aux {
};
} // namespace libtorrent

#ifdef __clang__
#pragma clang diagnostic pop
#endif

#endif
11 changes: 11 additions & 0 deletions include/libtorrent/bitfield.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ POSSIBILITY OF SUCH DAMAGE.
#include <cstring> // for memset and memcpy
#include <cstdint> // 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
Expand Down Expand Up @@ -332,4 +339,8 @@ namespace libtorrent {
};
}

#ifdef __clang__
#pragma clang diagnostic pop
#endif

#endif // TORRENT_BITFIELD_HPP_INCLUDED
3 changes: 2 additions & 1 deletion include/libtorrent/stat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ POSSIBILITY OF SUCH DAMAGE.

#include "libtorrent/config.hpp"
#include "libtorrent/assert.hpp"
#include "libtorrent/aux_/array.hpp"

namespace libtorrent {

Expand Down Expand Up @@ -279,7 +280,7 @@ namespace libtorrent {

private:

stat_channel m_stat[num_channels];
aux::array<stat_channel, num_channels> m_stat;
};

}
Expand Down
25 changes: 11 additions & 14 deletions src/alert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1440,8 +1440,7 @@ namespace {
return {};
#else
char ret[600];
static char const* const reason_str[] =
{
static aux::array<char const*, 8> const reason_str{{
"ip_filter",
"port_filter",
"i2p_mixed",
Expand All @@ -1450,7 +1449,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]);
Expand Down Expand Up @@ -1578,9 +1577,9 @@ namespace {
return {};
#else
char msg[200];
static char const* const msgs[] = {
static aux::array<char const*, 1> 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());
Expand Down Expand Up @@ -2226,8 +2225,8 @@ namespace {
#ifdef TORRENT_DISABLE_ALERT_MSG
return {};
#else
static char const* const mode[] =
{ "<==", "==>", "<<<", ">>>", "***" };
static aux::array<char const*, 5, direction_t> const mode{
{ "<==", "==>", "<<<", ">>>", "***" }};
return peer_alert::message() + " [" + print_endpoint(endpoint) + "] "
+ mode[direction] + " " + event_type + " [ " + log_message() + " ]";
#endif
Expand Down Expand Up @@ -2456,14 +2455,13 @@ namespace {
#ifdef TORRENT_DISABLE_ALERT_MSG
return {};
#else
static char const* const dht_modules[] =
{
static aux::array<char const*, 5, dht_module_t> const dht_modules{{
"tracker",
"node",
"routing_table",
"rpc_manager",
"traversal"
};
}};

char ret[900];
std::snprintf(ret, sizeof(ret), "DHT %s: %s", dht_modules[module]
Expand Down Expand Up @@ -2505,7 +2503,7 @@ namespace {

std::string msg = print_entry(print, true);

static char const* const prefix[2] = {"<==", "==>"};
static aux::array<char const*, 2, direction_t> const prefix{{"<==", "==>"}};
char buf[1024];
std::snprintf(buf, sizeof(buf), "%s [%s] %s", prefix[direction]
, print_endpoint(node).c_str(), msg.c_str());
Expand Down Expand Up @@ -2679,8 +2677,7 @@ namespace {
#ifdef TORRENT_DISABLE_ALERT_MSG
return {};
#else
static char const* const flag_names[] =
{
static aux::array<char const*, 17> const flag_names{{
"partial_ratio ",
"prioritize_partials ",
"rarest_first_partials ",
Expand All @@ -2698,7 +2695,7 @@ namespace {
"backup2 ",
"end_game ",
"extent_affinity ",
};
}};

std::string ret = peer_alert::message();

Expand Down
3 changes: 0 additions & 3 deletions src/torrent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10366,7 +10366,6 @@ namespace {
int num_peers = 0;
int num_downloaders = 0;
int missing_pieces = 0;
int num_interested = 0;
for (auto const p : m_connections)
{
TORRENT_INCREMENT(m_iterating_connections);
Expand All @@ -10382,8 +10381,6 @@ namespace {
if (p->share_mode()) continue;
if (p->upload_only()) continue;

if (p->is_peer_interested()) ++num_interested;

++num_downloaders;
missing_pieces += pieces_in_torrent - p->num_have_pieces();
}
Expand Down

0 comments on commit 2dd665a

Please sign in to comment.