From a59350687aa85dd63c47acbf125068f7e602f586 Mon Sep 17 00:00:00 2001 From: Alden Torres Date: Sat, 19 Nov 2016 21:14:16 -0500 Subject: [PATCH] fixed a few warnings related to signed/unsigned conversions (#1338) fixed a few warnings related to signed/unsigned conversions --- .../libtorrent/aux_/disable_warnings_push.hpp | 4 ++- include/libtorrent/aux_/suggest_piece.hpp | 3 +-- include/libtorrent/bdecode.hpp | 4 +-- include/libtorrent/config.hpp | 4 +-- .../libtorrent/peer_connection_interface.hpp | 1 - include/libtorrent/peer_list.hpp | 3 +-- include/libtorrent/piece_picker.hpp | 3 +-- include/libtorrent/sliding_average.hpp | 3 +-- include/libtorrent/socket.hpp | 2 +- include/libtorrent/stat.hpp | 27 ++++++++----------- include/libtorrent/torrent.hpp | 8 +++--- include/libtorrent/torrent_handle.hpp | 2 +- include/libtorrent/torrent_info.hpp | 2 +- src/stat.cpp | 8 ++---- src/torrent_info.cpp | 2 +- 15 files changed, 32 insertions(+), 44 deletions(-) diff --git a/include/libtorrent/aux_/disable_warnings_push.hpp b/include/libtorrent/aux_/disable_warnings_push.hpp index e0cb444bd..0c0a670f3 100644 --- a/include/libtorrent/aux_/disable_warnings_push.hpp +++ b/include/libtorrent/aux_/disable_warnings_push.hpp @@ -86,5 +86,7 @@ POSSIBILITY OF SUCH DAMAGE. #ifdef _MSC_VER #pragma warning(push, 1) // warning C4005: macro redefinition -#pragma warning( disable : 4005 ) +#pragma warning(disable : 4005) +// expression before comma has no effect; expected expression with side-effect +#pragma warning(disable : 4548) #endif diff --git a/include/libtorrent/aux_/suggest_piece.hpp b/include/libtorrent/aux_/suggest_piece.hpp index 6ff363cdf..6d0efb441 100644 --- a/include/libtorrent/aux_/suggest_piece.hpp +++ b/include/libtorrent/aux_/suggest_piece.hpp @@ -57,7 +57,7 @@ struct suggest_piece // is we add any piece to the result (p), the farther back the better. // the prioritization in p is the same, which means we have to first push // back and then reverse the items we put there. - for (int i = int(m_priority_pieces.size())-1; i >= 0; --i) + for (int i = int(m_priority_pieces.size()) - 1; i >= 0; --i) { int const piece = m_priority_pieces[i]; if (bits.get_bit(piece)) continue; @@ -126,4 +126,3 @@ private: }} #endif - diff --git a/include/libtorrent/bdecode.hpp b/include/libtorrent/bdecode.hpp index 4601ca9f7..4c3d724cc 100644 --- a/include/libtorrent/bdecode.hpp +++ b/include/libtorrent/bdecode.hpp @@ -187,7 +187,7 @@ struct bdecode_token : offset(off) , type(t) , next_item(next) - , header(type == string ? header_size - 2 : 0) + , header(type == string ? std::uint32_t(header_size - 2) : 0) { TORRENT_ASSERT(type != string || header_size >= 2); TORRENT_ASSERT(off <= max_offset); @@ -197,7 +197,7 @@ struct bdecode_token TORRENT_ASSERT(t >= 0 && t <= end); } - int start_offset() const { TORRENT_ASSERT(type == string); return header + 2; } + int start_offset() const { TORRENT_ASSERT(type == string); return int(header) + 2; } // offset into the bdecoded buffer where this node is std::uint32_t offset:29; diff --git a/include/libtorrent/config.hpp b/include/libtorrent/config.hpp index 787dbaa27..b81c3fa3e 100644 --- a/include/libtorrent/config.hpp +++ b/include/libtorrent/config.hpp @@ -544,7 +544,7 @@ POSSIBILITY OF SUCH DAMAGE. #define __has_builtin(x) 0 // for non-clang compilers #endif -#if (TORRENT_HAS_SSE && __GNUC__) +#if (TORRENT_HAS_SSE && defined __GNUC__) # define TORRENT_HAS_BUILTIN_CLZ 1 #elif (TORRENT_HAS_ARM && defined __GNUC__ && !defined __clang__) # define TORRENT_HAS_BUILTIN_CLZ 1 @@ -554,7 +554,7 @@ POSSIBILITY OF SUCH DAMAGE. # define TORRENT_HAS_BUILTIN_CLZ 0 #endif // TORRENT_HAS_BUILTIN_CLZ -#if (TORRENT_HAS_SSE && __GNUC__) +#if (TORRENT_HAS_SSE && defined __GNUC__) # define TORRENT_HAS_BUILTIN_CTZ 1 #elif (TORRENT_HAS_ARM && defined __GNUC__ && !defined __clang__) # define TORRENT_HAS_BUILTIN_CTZ 1 diff --git a/include/libtorrent/peer_connection_interface.hpp b/include/libtorrent/peer_connection_interface.hpp index fe3708c48..45789ab2e 100644 --- a/include/libtorrent/peer_connection_interface.hpp +++ b/include/libtorrent/peer_connection_interface.hpp @@ -73,4 +73,3 @@ namespace libtorrent } #endif - diff --git a/include/libtorrent/peer_list.hpp b/include/libtorrent/peer_list.hpp index 6e5d0267b..94c2a5522 100644 --- a/include/libtorrent/peer_list.hpp +++ b/include/libtorrent/peer_list.hpp @@ -201,7 +201,7 @@ namespace libtorrent bool has_peer(torrent_peer const* p) const; - int num_seeds() const { return m_num_seeds; } + int num_seeds() const { return int(m_num_seeds); } int num_connect_candidates() const { return m_num_connect_candidates; } void erase_peer(torrent_peer* p, torrent_state* state); @@ -280,4 +280,3 @@ namespace libtorrent } #endif // TORRENT_POLICY_HPP_INCLUDED - diff --git a/include/libtorrent/piece_picker.hpp b/include/libtorrent/piece_picker.hpp index de062c9cf..742407ae9 100644 --- a/include/libtorrent/piece_picker.hpp +++ b/include/libtorrent/piece_picker.hpp @@ -503,7 +503,7 @@ namespace libtorrent return piece_downloading; if (download_state == piece_full_reverse) return piece_full; - return download_state; + return int(download_state); } bool reverse() const @@ -808,4 +808,3 @@ namespace libtorrent } #endif // TORRENT_PIECE_PICKER_HPP_INCLUDED - diff --git a/include/libtorrent/sliding_average.hpp b/include/libtorrent/sliding_average.hpp index b3b32518a..a1384832b 100644 --- a/include/libtorrent/sliding_average.hpp +++ b/include/libtorrent/sliding_average.hpp @@ -103,7 +103,7 @@ struct average_accumulator // let the average roll over, but only be worth a // single sample m_num_samples = 1; - m_sample_sum = ret; + m_sample_sum = std::uint64_t(ret); return ret; } @@ -116,4 +116,3 @@ private: } #endif - diff --git a/include/libtorrent/socket.hpp b/include/libtorrent/socket.hpp index 8ac85c24d..17b0d17d4 100644 --- a/include/libtorrent/socket.hpp +++ b/include/libtorrent/socket.hpp @@ -144,7 +144,7 @@ namespace libtorrent #else using tos_t = int; #endif - explicit type_of_service(char val): m_value(val) {} + explicit type_of_service(char val) : m_value(tos_t(val)) {} template int level(Protocol const&) const { return IPPROTO_IP; } template diff --git a/include/libtorrent/stat.hpp b/include/libtorrent/stat.hpp index 8c9e89f34..e20cbf1fb 100644 --- a/include/libtorrent/stat.hpp +++ b/include/libtorrent/stat.hpp @@ -34,12 +34,9 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_STAT_HPP_INCLUDED #include -#include -#include #include #include -#include "libtorrent/invariant_check.hpp" #include "libtorrent/config.hpp" #include "libtorrent/assert.hpp" @@ -57,9 +54,9 @@ namespace libtorrent void operator+=(stat_channel const& s) { - TORRENT_ASSERT(m_counter < (std::numeric_limits::max)() - s.m_counter); + TORRENT_ASSERT(m_counter < (std::numeric_limits::max)() - s.m_counter); m_counter += s.m_counter; - TORRENT_ASSERT(m_total_counter < (std::numeric_limits::max)() - s.m_counter); + TORRENT_ASSERT(m_total_counter < (std::numeric_limits::max)() - s.m_counter); m_total_counter += s.m_counter; } @@ -67,26 +64,26 @@ namespace libtorrent { TORRENT_ASSERT(count >= 0); - TORRENT_ASSERT(m_counter < (std::numeric_limits::max)() - count); + TORRENT_ASSERT(m_counter < (std::numeric_limits::max)() - count); m_counter += count; - TORRENT_ASSERT(m_total_counter < (std::numeric_limits::max)() - count); + TORRENT_ASSERT(m_total_counter < (std::numeric_limits::max)() - count); m_total_counter += count; } // should be called once every second void second_tick(int tick_interval_ms); - int rate() const { return m_5_sec_average; } - int low_pass_rate() const { return m_5_sec_average; } + std::int32_t rate() const { return m_5_sec_average; } + std::int32_t low_pass_rate() const { return m_5_sec_average; } std::int64_t total() const { return m_total_counter; } void offset(std::int64_t c) { - TORRENT_ASSERT(m_total_counter < (std::numeric_limits::max)() - c); + TORRENT_ASSERT(m_total_counter < (std::numeric_limits::max)() - c); m_total_counter += c; } - int counter() const { return m_counter; } + std::int32_t counter() const { return m_counter; } void clear() { @@ -98,18 +95,17 @@ namespace libtorrent private: // total counters - std::uint64_t m_total_counter; + std::int64_t m_total_counter; // the accumulator for this second. - std::uint32_t m_counter; + std::int32_t m_counter; // sliding average - std::uint32_t m_5_sec_average; + std::int32_t m_5_sec_average; }; class TORRENT_EXTRA_EXPORT stat { - friend class invariant_access; public: void operator+=(const stat& s) { @@ -285,4 +281,3 @@ namespace libtorrent } #endif // TORRENT_STAT_HPP_INCLUDED - diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index beaa186cd..ab0632be6 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -381,7 +381,7 @@ namespace libtorrent , peer_request p); void on_disk_tick_done(disk_io_job const* j); - void set_progress_ppm(int p) { m_progress_ppm = p; } + void set_progress_ppm(int p) { m_progress_ppm = std::uint32_t(p); } struct read_piece_struct { boost::shared_array piece_data; @@ -566,9 +566,9 @@ namespace libtorrent peer_class_t peer_class() const { return peer_class_t(m_peer_class); } void set_max_uploads(int limit, bool state_update = true); - int max_uploads() const { return m_max_uploads; } + int max_uploads() const { return int(m_max_uploads); } void set_max_connections(int limit, bool state_update = true); - int max_connections() const { return m_max_connections; } + int max_connections() const { return int(m_max_connections); } // -------------------------------------------- // PEER MANAGEMENT @@ -1615,7 +1615,7 @@ namespace libtorrent // progress parts per million (the number of // millionths of completeness) - unsigned int m_progress_ppm:20; + std::uint32_t m_progress_ppm:20; #if TORRENT_USE_ASSERTS // set to true when torrent is start()ed. It may only be started once diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index 184486ad9..8def9d438 100644 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -143,7 +143,7 @@ namespace libtorrent private: #if TORRENT_USE_IPV6 // the type of the addr union - unsigned is_v6_addr:1; + bool is_v6_addr:1; #endif }; diff --git a/include/libtorrent/torrent_info.hpp b/include/libtorrent/torrent_info.hpp index 5f6be655e..5287f812d 100644 --- a/include/libtorrent/torrent_info.hpp +++ b/include/libtorrent/torrent_info.hpp @@ -605,7 +605,7 @@ namespace libtorrent sha1_hash m_info_hash; // the number of bytes in m_info_section - std::uint32_t m_info_section_size = 0; + std::int32_t m_info_section_size = 0; // the index to the first leaf. This is where the hash for the // first piece is stored diff --git a/src/stat.cpp b/src/stat.cpp index 7abc53931..72e8df05b 100644 --- a/src/stat.cpp +++ b/src/stat.cpp @@ -30,20 +30,16 @@ POSSIBILITY OF SUCH DAMAGE. */ -#include -#include - #include "libtorrent/stat.hpp" namespace libtorrent { void stat_channel::second_tick(int tick_interval_ms) { - int sample = int(std::int64_t(m_counter) * 1000 / tick_interval_ms); + std::int64_t sample = std::int64_t(m_counter) * 1000 / tick_interval_ms; TORRENT_ASSERT(sample >= 0); - m_5_sec_average = std::int64_t(m_5_sec_average) * 4 / 5 + sample / 5; + m_5_sec_average = std::int32_t(std::int64_t(m_5_sec_average) * 4 / 5 + sample / 5); m_counter = 0; } } - diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index 831fad035..41f6caa6d 100644 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -1088,7 +1088,7 @@ namespace libtorrent m_info_section.reset(new char[m_info_section_size]); std::memcpy(m_info_section.get(), section.data(), m_info_section_size); TORRENT_ASSERT(section[0] == 'd'); - TORRENT_ASSERT(section[m_info_section_size-1] == 'e'); + TORRENT_ASSERT(section[m_info_section_size - 1] == 'e'); // when translating a pointer that points into the 'info' tree's // backing buffer, into a pointer to our copy of the info section,