fixing sign-conversion warnings, part 18

This commit is contained in:
Alden Torres 2017-02-20 14:51:07 -05:00 committed by Arvid Norberg
parent d1e88ae98b
commit 267cab6822
5 changed files with 33 additions and 32 deletions

View File

@ -42,6 +42,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/assert.hpp" #include "libtorrent/assert.hpp"
#include "libtorrent/aux_/byteswap.hpp" #include "libtorrent/aux_/byteswap.hpp"
#include "libtorrent/aux_/ffs.hpp" #include "libtorrent/aux_/ffs.hpp"
#include "libtorrent/aux_/typed_span.hpp"
#if TORRENT_USE_IOSTREAM #if TORRENT_USE_IOSTREAM
#include <iosfwd> #include <iosfwd>
@ -52,8 +53,8 @@ namespace libtorrent
// TODO: find a better place for these functions // TODO: find a better place for these functions
namespace aux namespace aux
{ {
TORRENT_EXTRA_EXPORT void bits_shift_left(span<std::uint32_t> number, int n); TORRENT_EXTRA_EXPORT void bits_shift_left(typed_span<std::uint32_t> number, int n);
TORRENT_EXTRA_EXPORT void bits_shift_right(span<std::uint32_t> number, int n); TORRENT_EXTRA_EXPORT void bits_shift_right(typed_span<std::uint32_t> number, int n);
} }
// This type holds an N digest or any other kind of N bits // This type holds an N digest or any other kind of N bits
@ -70,7 +71,7 @@ namespace libtorrent
public: public:
// the size of the hash in bytes // the size of the hash in bytes
static constexpr size_t size() { return N / 8; } static constexpr std::size_t size() { return N / 8; }
// constructs an all-zero digest // constructs an all-zero digest
digest32() { clear(); } digest32() { clear(); }
@ -122,7 +123,7 @@ namespace libtorrent
void assign(span<char const> s) void assign(span<char const> s)
{ {
TORRENT_ASSERT(s.size() >= N / 8); TORRENT_ASSERT(s.size() >= N / 8);
size_t const sl = s.size() < size() ? s.size() : size(); std::size_t const sl = s.size() < size() ? s.size() : size();
std::memcpy(m_number, s.data(), sl); std::memcpy(m_number, s.data(), sl);
} }
void assign(char const* str) { std::memcpy(m_number, str, size()); } void assign(char const* str) { std::memcpy(m_number, str, size()); }

View File

@ -1093,13 +1093,13 @@ namespace libtorrent
void session_handle::set_alert_mask(std::uint32_t m) void session_handle::set_alert_mask(std::uint32_t m)
{ {
settings_pack p; settings_pack p;
p.set_int(settings_pack::alert_mask, m); p.set_int(settings_pack::alert_mask, int(m));
apply_settings(std::move(p)); apply_settings(std::move(p));
} }
std::uint32_t session_handle::get_alert_mask() const std::uint32_t session_handle::get_alert_mask() const
{ {
return get_settings().get_int(settings_pack::alert_mask); return std::uint32_t(get_settings().get_int(settings_pack::alert_mask));
} }
void session_handle::start_lsd() void session_handle::start_lsd()

View File

@ -503,7 +503,7 @@ namespace aux {
{ {
if (pack.has_val(settings_pack::alert_mask)) if (pack.has_val(settings_pack::alert_mask))
{ {
m_alerts.set_alert_mask(pack.get_int(settings_pack::alert_mask)); m_alerts.set_alert_mask(std::uint32_t(pack.get_int(settings_pack::alert_mask)));
} }
#ifndef TORRENT_DISABLE_LOGGING #ifndef TORRENT_DISABLE_LOGGING
@ -5504,18 +5504,18 @@ namespace aux {
s.dht_total_allocations = 0; s.dht_total_allocations = 0;
} }
s.utp_stats.packet_loss = m_stats_counters[counters::utp_packet_loss]; s.utp_stats.packet_loss = std::uint64_t(m_stats_counters[counters::utp_packet_loss]);
s.utp_stats.timeout = m_stats_counters[counters::utp_timeout]; s.utp_stats.timeout = std::uint64_t(m_stats_counters[counters::utp_timeout]);
s.utp_stats.packets_in = m_stats_counters[counters::utp_packets_in]; s.utp_stats.packets_in = std::uint64_t(m_stats_counters[counters::utp_packets_in]);
s.utp_stats.packets_out = m_stats_counters[counters::utp_packets_out]; s.utp_stats.packets_out = std::uint64_t(m_stats_counters[counters::utp_packets_out]);
s.utp_stats.fast_retransmit = m_stats_counters[counters::utp_fast_retransmit]; s.utp_stats.fast_retransmit = std::uint64_t(m_stats_counters[counters::utp_fast_retransmit]);
s.utp_stats.packet_resend = m_stats_counters[counters::utp_packet_resend]; s.utp_stats.packet_resend = std::uint64_t(m_stats_counters[counters::utp_packet_resend]);
s.utp_stats.samples_above_target = m_stats_counters[counters::utp_samples_above_target]; s.utp_stats.samples_above_target = std::uint64_t(m_stats_counters[counters::utp_samples_above_target]);
s.utp_stats.samples_below_target = m_stats_counters[counters::utp_samples_below_target]; s.utp_stats.samples_below_target = std::uint64_t(m_stats_counters[counters::utp_samples_below_target]);
s.utp_stats.payload_pkts_in = m_stats_counters[counters::utp_payload_pkts_in]; s.utp_stats.payload_pkts_in = std::uint64_t(m_stats_counters[counters::utp_payload_pkts_in]);
s.utp_stats.payload_pkts_out = m_stats_counters[counters::utp_payload_pkts_out]; s.utp_stats.payload_pkts_out = std::uint64_t(m_stats_counters[counters::utp_payload_pkts_out]);
s.utp_stats.invalid_pkts_in = m_stats_counters[counters::utp_invalid_pkts_in]; s.utp_stats.invalid_pkts_in = std::uint64_t(m_stats_counters[counters::utp_invalid_pkts_in]);
s.utp_stats.redundant_pkts_in = m_stats_counters[counters::utp_redundant_pkts_in]; s.utp_stats.redundant_pkts_in = std::uint64_t(m_stats_counters[counters::utp_redundant_pkts_in]);
s.utp_stats.num_idle = int(m_stats_counters[counters::num_utp_idle]); s.utp_stats.num_idle = int(m_stats_counters[counters::num_utp_idle]);
s.utp_stats.num_syn_sent = int(m_stats_counters[counters::num_utp_syn_sent]); s.utp_stats.num_syn_sent = int(m_stats_counters[counters::num_utp_syn_sent]);
@ -6365,7 +6365,7 @@ namespace aux {
void session_impl::update_alert_mask() void session_impl::update_alert_mask()
{ {
m_alerts.set_alert_mask(m_settings.get_int(settings_pack::alert_mask)); m_alerts.set_alert_mask(std::uint32_t(m_settings.get_int(settings_pack::alert_mask)));
} }
void session_impl::pop_alerts(std::vector<alert*>* alerts) void session_impl::pop_alerts(std::vector<alert*>* alerts)
@ -6449,7 +6449,7 @@ namespace aux {
std::size_t session_impl::set_alert_queue_size_limit(std::size_t queue_size_limit_) std::size_t session_impl::set_alert_queue_size_limit(std::size_t queue_size_limit_)
{ {
m_settings.set_int(settings_pack::alert_queue_size, int(queue_size_limit_)); m_settings.set_int(settings_pack::alert_queue_size, int(queue_size_limit_));
return m_alerts.set_alert_queue_size_limit(int(queue_size_limit_)); return std::size_t(m_alerts.set_alert_queue_size_limit(int(queue_size_limit_)));
} }
#endif #endif

View File

@ -62,23 +62,23 @@ namespace libtorrent
namespace aux namespace aux
{ {
void bits_shift_left(span<std::uint32_t> number, int n) void bits_shift_left(typed_span<std::uint32_t> number, int n)
{ {
TORRENT_ASSERT(n >= 0); TORRENT_ASSERT(n >= 0);
int const num_words = n / 32; int const num_words = n / 32;
int const number_size = int(number.size()); int const number_size = number.end_index();
if (num_words >= number_size) if (num_words >= number_size)
{ {
std::memset(number.data(), 0, number_size * 4); std::memset(number.data(), 0, number.size() * 4);
return; return;
} }
if (num_words > 0) if (num_words > 0)
{ {
std::memmove(number.data(), number.data() + num_words std::memmove(number.data(), number.data() + num_words
, (number_size - num_words) * sizeof(std::uint32_t)); , std::size_t(number_size - num_words) * sizeof(std::uint32_t));
std::memset(number.data() + (number_size - num_words) std::memset(number.data() + (number_size - num_words)
, 0, num_words * sizeof(std::uint32_t)); , 0, std::size_t(num_words) * sizeof(std::uint32_t));
n -= num_words * 32; n -= num_words * 32;
} }
if (n > 0) if (n > 0)
@ -100,21 +100,21 @@ namespace aux
} }
} }
void bits_shift_right(span<std::uint32_t> number, int n) void bits_shift_right(typed_span<std::uint32_t> number, int n)
{ {
TORRENT_ASSERT(n >= 0); TORRENT_ASSERT(n >= 0);
int const num_words = n / 32; int const num_words = n / 32;
int const number_size = int(number.size()); int const number_size = number.end_index();
if (num_words >= number_size) if (num_words >= number_size)
{ {
std::memset(number.data(), 0, number_size * 4); std::memset(number.data(), 0, number.size() * 4);
return; return;
} }
if (num_words > 0) if (num_words > 0)
{ {
std::memmove(number.data() + num_words std::memmove(number.data() + num_words
, number.data(), (number_size - num_words) * sizeof(std::uint32_t)); , number.data(), std::size_t(number_size - num_words) * sizeof(std::uint32_t));
std::memset(number.data(), 0, num_words * sizeof(std::uint32_t)); std::memset(number.data(), 0, std::size_t(num_words) * sizeof(std::uint32_t));
n -= num_words * 32; n -= num_words * 32;
} }
if (n > 0) if (n > 0)

View File

@ -134,7 +134,7 @@ namespace libtorrent
start = i; start = i;
// find end of attribute name // find end of attribute name
for (; i != tag_end && *i != '=' && !is_space(*i); ++i); for (; i != tag_end && *i != '=' && !is_space(*i); ++i);
std::size_t const name_len = i - start; std::size_t const name_len = std::size_t(i - start);
// look for equality sign // look for equality sign
for (; i != tag_end && *i != '='; ++i); for (; i != tag_end && *i != '='; ++i);