Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix warnings in new versions of clang #7600

Merged
merged 12 commits into from
Feb 18, 2024
3 changes: 2 additions & 1 deletion include/libtorrent/aux_/bandwidth_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<bandwidth_socket> peer
, int blk, int priority, bandwidth_channel** chan, int num_channels);
, int blk, int priority, span<bandwidth_channel*> channels);

#if TORRENT_USE_INVARIANT_CHECKS
void check_invariant() const;
Expand Down
11 changes: 11 additions & 0 deletions include/libtorrent/aux_/heterogeneous_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ see LICENSE file.
#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 @@ -274,4 +281,8 @@ namespace aux {
};
} // namespace libtorrent

#ifdef __clang__
#pragma clang diagnostic pop
#endif

#endif
2 changes: 2 additions & 0 deletions include/libtorrent/aux_/netlink_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion include/libtorrent/aux_/peer_connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bandwidth_state_flags_t, 2> m_channel_state;

protected:
aux::receive_buffer m_recv_buffer;
Expand Down
3 changes: 2 additions & 1 deletion include/libtorrent/aux_/stat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ see LICENSE file.

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

namespace libtorrent::aux {

Expand Down Expand Up @@ -256,7 +257,7 @@ namespace libtorrent::aux {

private:

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

}
Expand Down
11 changes: 11 additions & 0 deletions include/libtorrent/bitfield.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ see LICENSE file.
#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 @@ -330,4 +337,8 @@ namespace libtorrent {
};
}

#ifdef __clang__
#pragma clang diagnostic pop
#endif

#endif // TORRENT_BITFIELD_HPP_INCLUDED
3 changes: 2 additions & 1 deletion include/libtorrent/peer_class.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ see LICENSE file.
#include "libtorrent/aux_/deque.hpp"

#include <vector>
#include <array>
#include <string>
#include <cstdint>
#include <memory>
Expand Down Expand Up @@ -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<int, 2> priority;

// the name of this peer class
std::string label;
Expand Down
11 changes: 11 additions & 0 deletions include/libtorrent/span.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename T>
struct span
{
Expand Down Expand Up @@ -153,6 +160,10 @@ namespace aux {
difference_type m_len;
};

#ifdef __clang__
#pragma clang diagnostic pop
#endif

template <class T, class U>
inline bool operator==(span<T> const& lhs, span<U> const& rhs)
{
Expand Down
31 changes: 14 additions & 17 deletions src/alert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ namespace libtorrent {
TORRENT_UNUSED(i);
return "";
#else
static char const* const warning_str[] =
static aux::array<char const*, 11> const warning_str{
{
"max outstanding disk writes reached",
"max outstanding piece requests reached",
Expand All @@ -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
}
Expand Down Expand Up @@ -1370,8 +1370,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 @@ -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]);
Expand Down Expand Up @@ -1508,9 +1507,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 @@ -2156,8 +2155,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 @@ -2385,14 +2384,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 @@ -2434,7 +2432,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 @@ -2589,8 +2587,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 @@ -2608,7 +2605,7 @@ namespace {
"backup2 ",
"end_game ",
"extent_affinity ",
};
}};

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

Expand Down
22 changes: 21 additions & 1 deletion src/assert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,16 @@ see LICENSE file.

#include <cxxabi.h>

#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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -113,6 +123,12 @@ std::string demangle(char const* name) { return name; }
#if TORRENT_USE_EXECINFO
#include <execinfo.h>

#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*)
Expand All @@ -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"
Expand Down
10 changes: 5 additions & 5 deletions src/bandwidth_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bandwidth_socket> peer
, int const blk, int const priority, bandwidth_channel** chan, int const num_channels)
, int const blk, int const priority, span<bandwidth_channel*> channels)
{
INVARIANT_CHECK;
if (m_abort) return 0;
Expand All @@ -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
Expand All @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions src/bdecode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1160,3 +1167,7 @@ namespace aux {
return ret;
}
}

#ifdef __clang__
#pragma clang diagnostic pop
#endif
12 changes: 12 additions & 0 deletions src/bitfield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ see LICENSE file.
#include <intrin.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 {

bool bitfield::all_set() const noexcept
Expand Down Expand Up @@ -225,3 +232,8 @@ namespace libtorrent {
static_assert(std::is_nothrow_default_constructible<typed_bitfield<int>>::value
, "should be nothrow default constructible");
}

#ifdef __clang__
#pragma clang diagnostic pop
#endif

Loading
Loading