diff --git a/include/libtorrent/sha1_hash.hpp b/include/libtorrent/sha1_hash.hpp index e89034894..292e6bca8 100644 --- a/include/libtorrent/sha1_hash.hpp +++ b/include/libtorrent/sha1_hash.hpp @@ -42,6 +42,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/assert.hpp" #include "libtorrent/aux_/byteswap.hpp" #include "libtorrent/aux_/ffs.hpp" +#include "libtorrent/aux_/typed_span.hpp" #if TORRENT_USE_IOSTREAM #include @@ -52,8 +53,8 @@ namespace libtorrent // TODO: find a better place for these functions namespace aux { - TORRENT_EXTRA_EXPORT void bits_shift_left(span number, int n); - TORRENT_EXTRA_EXPORT void bits_shift_right(span number, int n); + TORRENT_EXTRA_EXPORT void bits_shift_left(typed_span number, int n); + TORRENT_EXTRA_EXPORT void bits_shift_right(typed_span number, int n); } // This type holds an N digest or any other kind of N bits @@ -70,7 +71,7 @@ namespace libtorrent public: // 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 digest32() { clear(); } @@ -122,7 +123,7 @@ namespace libtorrent void assign(span s) { 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); } void assign(char const* str) { std::memcpy(m_number, str, size()); } diff --git a/src/session_handle.cpp b/src/session_handle.cpp index d91b9c9d4..6f4fcfddb 100644 --- a/src/session_handle.cpp +++ b/src/session_handle.cpp @@ -1093,13 +1093,13 @@ namespace libtorrent void session_handle::set_alert_mask(std::uint32_t m) { 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)); } 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() diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 24408cc7a..e8c713239 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -503,7 +503,7 @@ namespace aux { { 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 @@ -5504,18 +5504,18 @@ namespace aux { s.dht_total_allocations = 0; } - s.utp_stats.packet_loss = m_stats_counters[counters::utp_packet_loss]; - s.utp_stats.timeout = m_stats_counters[counters::utp_timeout]; - s.utp_stats.packets_in = m_stats_counters[counters::utp_packets_in]; - s.utp_stats.packets_out = m_stats_counters[counters::utp_packets_out]; - s.utp_stats.fast_retransmit = m_stats_counters[counters::utp_fast_retransmit]; - s.utp_stats.packet_resend = 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_below_target = 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_out = 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.redundant_pkts_in = m_stats_counters[counters::utp_redundant_pkts_in]; + s.utp_stats.packet_loss = std::uint64_t(m_stats_counters[counters::utp_packet_loss]); + s.utp_stats.timeout = std::uint64_t(m_stats_counters[counters::utp_timeout]); + s.utp_stats.packets_in = std::uint64_t(m_stats_counters[counters::utp_packets_in]); + s.utp_stats.packets_out = std::uint64_t(m_stats_counters[counters::utp_packets_out]); + s.utp_stats.fast_retransmit = std::uint64_t(m_stats_counters[counters::utp_fast_retransmit]); + s.utp_stats.packet_resend = std::uint64_t(m_stats_counters[counters::utp_packet_resend]); + s.utp_stats.samples_above_target = std::uint64_t(m_stats_counters[counters::utp_samples_above_target]); + s.utp_stats.samples_below_target = std::uint64_t(m_stats_counters[counters::utp_samples_below_target]); + s.utp_stats.payload_pkts_in = std::uint64_t(m_stats_counters[counters::utp_payload_pkts_in]); + s.utp_stats.payload_pkts_out = std::uint64_t(m_stats_counters[counters::utp_payload_pkts_out]); + s.utp_stats.invalid_pkts_in = std::uint64_t(m_stats_counters[counters::utp_invalid_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_syn_sent = int(m_stats_counters[counters::num_utp_syn_sent]); @@ -6365,7 +6365,7 @@ namespace aux { 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* alerts) @@ -6449,7 +6449,7 @@ namespace aux { 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_)); - 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 diff --git a/src/sha1_hash.cpp b/src/sha1_hash.cpp index 673f1c503..8a4ed4f88 100644 --- a/src/sha1_hash.cpp +++ b/src/sha1_hash.cpp @@ -62,23 +62,23 @@ namespace libtorrent namespace aux { - void bits_shift_left(span number, int n) + void bits_shift_left(typed_span number, int n) { TORRENT_ASSERT(n >= 0); 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) { - std::memset(number.data(), 0, number_size * 4); + std::memset(number.data(), 0, number.size() * 4); return; } if (num_words > 0) { 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) - , 0, num_words * sizeof(std::uint32_t)); + , 0, std::size_t(num_words) * sizeof(std::uint32_t)); n -= num_words * 32; } if (n > 0) @@ -100,21 +100,21 @@ namespace aux } } - void bits_shift_right(span number, int n) + void bits_shift_right(typed_span number, int n) { TORRENT_ASSERT(n >= 0); 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) { - std::memset(number.data(), 0, number_size * 4); + std::memset(number.data(), 0, number.size() * 4); return; } if (num_words > 0) { std::memmove(number.data() + num_words - , number.data(), (number_size - num_words) * sizeof(std::uint32_t)); - std::memset(number.data(), 0, num_words * sizeof(std::uint32_t)); + , number.data(), std::size_t(number_size - num_words) * sizeof(std::uint32_t)); + std::memset(number.data(), 0, std::size_t(num_words) * sizeof(std::uint32_t)); n -= num_words * 32; } if (n > 0) diff --git a/src/xml_parse.cpp b/src/xml_parse.cpp index c839863fc..a984fdc4f 100644 --- a/src/xml_parse.cpp +++ b/src/xml_parse.cpp @@ -134,7 +134,7 @@ namespace libtorrent start = i; // find end of attribute name 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 for (; i != tag_end && *i != '='; ++i);