From de9d777c9c79978093d56c8f11be84f4896f1739 Mon Sep 17 00:00:00 2001 From: Alden Torres Date: Sun, 26 Feb 2017 12:08:35 -0500 Subject: [PATCH] fixing sign-conversion warnings, part 22 --- src/packet_buffer.cpp | 5 ++--- src/session_impl.cpp | 2 +- src/torrent.cpp | 10 +++++----- src/utp_stream.cpp | 14 +++++++------- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/packet_buffer.cpp b/src/packet_buffer.cpp index e2112b2f9..275b4ffe6 100644 --- a/src/packet_buffer.cpp +++ b/src/packet_buffer.cpp @@ -45,11 +45,11 @@ namespace libtorrent { void packet_buffer::check_invariant() const { int count = 0; - for (int i = 0; i < int(m_capacity); ++i) + for (int i = 0; i < m_capacity; ++i) { count += m_storage[i] ? 1 : 0; } - TORRENT_ASSERT(count == int(m_size)); + TORRENT_ASSERT(count == m_size); } #endif @@ -192,4 +192,3 @@ namespace libtorrent { return old_value; } } - diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 1d86372c5..9f1ed768d 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -2618,7 +2618,7 @@ namespace aux { #pragma clang diagnostic ignored "-Wdeprecated-declarations" #endif // add the current time to the PRNG, to add more unpredictability - std::uint64_t now = clock_type::now().time_since_epoch().count(); + std::int64_t now = clock_type::now().time_since_epoch().count(); // assume 12 bits of entropy (i.e. about 8 milliseconds) RAND_add(&now, 8, 1.5); #ifdef TORRENT_MACOS_DEPRECATED_LIBCRYPTO diff --git a/src/torrent.cpp b/src/torrent.cpp index df92d97e7..2fd98f9bd 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -1421,14 +1421,14 @@ namespace libtorrent ASN1_IA5STRING* domain = gen->d.dNSName; if (domain->type != V_ASN1_IA5STRING || !domain->data || !domain->length) continue; const char* torrent_name = reinterpret_cast(domain->data); - std::size_t name_length = domain->length; + std::size_t name_length = aux::numeric_cast(domain->length); #ifndef TORRENT_DISABLE_LOGGING if (i > 1) names += " | n: "; names.append(torrent_name, name_length); #endif - if (strncmp(torrent_name, "*", name_length) == 0 - || strncmp(torrent_name, m_torrent_file->name().c_str(), name_length) == 0) + if (std::strncmp(torrent_name, "*", name_length) == 0 + || std::strncmp(torrent_name, m_torrent_file->name().c_str(), name_length) == 0) { #ifndef TORRENT_DISABLE_LOGGING match = true; @@ -1454,7 +1454,7 @@ namespace libtorrent if (common_name && common_name->data && common_name->length) { const char* torrent_name = reinterpret_cast(common_name->data); - std::size_t name_length = common_name->length; + std::size_t name_length = aux::numeric_cast(common_name->length); #ifndef TORRENT_DISABLE_LOGGING if (!names.empty()) names += " | n: "; @@ -1488,7 +1488,7 @@ namespace libtorrent // this is needed for openssl < 1.0 to decrypt keys created by openssl 1.0+ OpenSSL_add_all_algorithms(); - std::uint64_t const now = clock_type::now().time_since_epoch().count(); + std::int64_t const now = clock_type::now().time_since_epoch().count(); // assume 9 bits of entropy (i.e. about 1 millisecond) RAND_add(&now, 8, 1.125); RAND_add(&info_hash()[0], 20, 3); diff --git a/src/utp_stream.cpp b/src/utp_stream.cpp index f9cf8f0e5..5d2377b14 100644 --- a/src/utp_stream.cpp +++ b/src/utp_stream.cpp @@ -299,7 +299,7 @@ struct utp_socket_impl bool consume_incoming_data( utp_header const* ph, std::uint8_t const* ptr, int payload_size, time_point now); void update_mtu_limits(); - void experienced_loss(int seq_nr); + void experienced_loss(std::uint32_t seq_nr); void set_state(int s); @@ -1439,7 +1439,7 @@ std::pair utp_socket_impl::parse_sack(std::uint16_t const pa if (size == 0) return { 0u, 0 }; // this is the sequence number the current bit represents - int ack_nr = (packet_ack + 2) & ACK_MASK; + std::uint32_t ack_nr = (packet_ack + 2) & ACK_MASK; #if TORRENT_VERBOSE_UTP_LOG std::string bitmask; @@ -1464,7 +1464,7 @@ std::pair utp_socket_impl::parse_sack(std::uint16_t const pa int dups = 0; // the sequence number of the last ACKed packet - int last_ack = packet_ack; + std::uint32_t last_ack = packet_ack; int acked_bytes = 0; std::uint32_t min_rtt = std::numeric_limits::max(); @@ -2181,7 +2181,7 @@ bool utp_socket_impl::resend_packet(packet* p, bool fast_resend) return !m_stalled; } -void utp_socket_impl::experienced_loss(int const seq_nr) +void utp_socket_impl::experienced_loss(std::uint32_t const seq_nr) { INVARIANT_CHECK; @@ -2828,7 +2828,7 @@ bool utp_socket_impl::incoming_packet(span buf int const size = int(buf.size()); ptr += sizeof(utp_header); - unsigned int extension = ph->extension; + std::uint8_t extension = ph->extension; while (extension) { // invalid packet. It says it has an extension header @@ -2839,7 +2839,7 @@ bool utp_socket_impl::incoming_packet(span buf m_sm.inc_stats_counter(counters::utp_invalid_pkts_in); return true; } - int next_extension = *ptr++; + std::uint8_t const next_extension = *ptr++; int len = *ptr++; if (len < 0) { @@ -2848,7 +2848,7 @@ bool utp_socket_impl::incoming_packet(span buf m_sm.inc_stats_counter(counters::utp_invalid_pkts_in); return true; } - if (ptr - buf.data() + len > ptrdiff_t(size)) + if (ptr - buf.data() + len > size) { UTP_LOG("%8p: ERROR: invalid extension header size:%d packet:%d\n" , static_cast(this), len, int(ptr - buf.data()));