fixed a few warnings related to signed/unsigned conversions (#1338)
fixed a few warnings related to signed/unsigned conversions
This commit is contained in:
parent
998daf6e0e
commit
a59350687a
|
@ -86,5 +86,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#pragma warning(push, 1)
|
#pragma warning(push, 1)
|
||||||
// warning C4005: macro redefinition
|
// 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
|
#endif
|
||||||
|
|
|
@ -57,7 +57,7 @@ struct suggest_piece
|
||||||
// is we add any piece to the result (p), the farther back the better.
|
// 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
|
// the prioritization in p is the same, which means we have to first push
|
||||||
// back and then reverse the items we put there.
|
// 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];
|
int const piece = m_priority_pieces[i];
|
||||||
if (bits.get_bit(piece)) continue;
|
if (bits.get_bit(piece)) continue;
|
||||||
|
@ -126,4 +126,3 @@ private:
|
||||||
}}
|
}}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -187,7 +187,7 @@ struct bdecode_token
|
||||||
: offset(off)
|
: offset(off)
|
||||||
, type(t)
|
, type(t)
|
||||||
, next_item(next)
|
, 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(type != string || header_size >= 2);
|
||||||
TORRENT_ASSERT(off <= max_offset);
|
TORRENT_ASSERT(off <= max_offset);
|
||||||
|
@ -197,7 +197,7 @@ struct bdecode_token
|
||||||
TORRENT_ASSERT(t >= 0 && t <= end);
|
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
|
// offset into the bdecoded buffer where this node is
|
||||||
std::uint32_t offset:29;
|
std::uint32_t offset:29;
|
||||||
|
|
|
@ -544,7 +544,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#define __has_builtin(x) 0 // for non-clang compilers
|
#define __has_builtin(x) 0 // for non-clang compilers
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (TORRENT_HAS_SSE && __GNUC__)
|
#if (TORRENT_HAS_SSE && defined __GNUC__)
|
||||||
# define TORRENT_HAS_BUILTIN_CLZ 1
|
# define TORRENT_HAS_BUILTIN_CLZ 1
|
||||||
#elif (TORRENT_HAS_ARM && defined __GNUC__ && !defined __clang__)
|
#elif (TORRENT_HAS_ARM && defined __GNUC__ && !defined __clang__)
|
||||||
# define TORRENT_HAS_BUILTIN_CLZ 1
|
# define TORRENT_HAS_BUILTIN_CLZ 1
|
||||||
|
@ -554,7 +554,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
# define TORRENT_HAS_BUILTIN_CLZ 0
|
# define TORRENT_HAS_BUILTIN_CLZ 0
|
||||||
#endif // TORRENT_HAS_BUILTIN_CLZ
|
#endif // TORRENT_HAS_BUILTIN_CLZ
|
||||||
|
|
||||||
#if (TORRENT_HAS_SSE && __GNUC__)
|
#if (TORRENT_HAS_SSE && defined __GNUC__)
|
||||||
# define TORRENT_HAS_BUILTIN_CTZ 1
|
# define TORRENT_HAS_BUILTIN_CTZ 1
|
||||||
#elif (TORRENT_HAS_ARM && defined __GNUC__ && !defined __clang__)
|
#elif (TORRENT_HAS_ARM && defined __GNUC__ && !defined __clang__)
|
||||||
# define TORRENT_HAS_BUILTIN_CTZ 1
|
# define TORRENT_HAS_BUILTIN_CTZ 1
|
||||||
|
|
|
@ -73,4 +73,3 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -201,7 +201,7 @@ namespace libtorrent
|
||||||
|
|
||||||
bool has_peer(torrent_peer const* p) const;
|
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; }
|
int num_connect_candidates() const { return m_num_connect_candidates; }
|
||||||
|
|
||||||
void erase_peer(torrent_peer* p, torrent_state* state);
|
void erase_peer(torrent_peer* p, torrent_state* state);
|
||||||
|
@ -280,4 +280,3 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // TORRENT_POLICY_HPP_INCLUDED
|
#endif // TORRENT_POLICY_HPP_INCLUDED
|
||||||
|
|
||||||
|
|
|
@ -503,7 +503,7 @@ namespace libtorrent
|
||||||
return piece_downloading;
|
return piece_downloading;
|
||||||
if (download_state == piece_full_reverse)
|
if (download_state == piece_full_reverse)
|
||||||
return piece_full;
|
return piece_full;
|
||||||
return download_state;
|
return int(download_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool reverse() const
|
bool reverse() const
|
||||||
|
@ -808,4 +808,3 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // TORRENT_PIECE_PICKER_HPP_INCLUDED
|
#endif // TORRENT_PIECE_PICKER_HPP_INCLUDED
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,7 @@ struct average_accumulator
|
||||||
// let the average roll over, but only be worth a
|
// let the average roll over, but only be worth a
|
||||||
// single sample
|
// single sample
|
||||||
m_num_samples = 1;
|
m_num_samples = 1;
|
||||||
m_sample_sum = ret;
|
m_sample_sum = std::uint64_t(ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,4 +116,3 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -144,7 +144,7 @@ namespace libtorrent
|
||||||
#else
|
#else
|
||||||
using tos_t = int;
|
using tos_t = int;
|
||||||
#endif
|
#endif
|
||||||
explicit type_of_service(char val): m_value(val) {}
|
explicit type_of_service(char val) : m_value(tos_t(val)) {}
|
||||||
template<class Protocol>
|
template<class Protocol>
|
||||||
int level(Protocol const&) const { return IPPROTO_IP; }
|
int level(Protocol const&) const { return IPPROTO_IP; }
|
||||||
template<class Protocol>
|
template<class Protocol>
|
||||||
|
|
|
@ -34,12 +34,9 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#define TORRENT_STAT_HPP_INCLUDED
|
#define TORRENT_STAT_HPP_INCLUDED
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <vector>
|
|
||||||
#include <cstring>
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
#include "libtorrent/invariant_check.hpp"
|
|
||||||
#include "libtorrent/config.hpp"
|
#include "libtorrent/config.hpp"
|
||||||
#include "libtorrent/assert.hpp"
|
#include "libtorrent/assert.hpp"
|
||||||
|
|
||||||
|
@ -57,9 +54,9 @@ namespace libtorrent
|
||||||
|
|
||||||
void operator+=(stat_channel const& s)
|
void operator+=(stat_channel const& s)
|
||||||
{
|
{
|
||||||
TORRENT_ASSERT(m_counter < (std::numeric_limits<std::uint32_t>::max)() - s.m_counter);
|
TORRENT_ASSERT(m_counter < (std::numeric_limits<std::int32_t>::max)() - s.m_counter);
|
||||||
m_counter += s.m_counter;
|
m_counter += s.m_counter;
|
||||||
TORRENT_ASSERT(m_total_counter < (std::numeric_limits<std::uint64_t>::max)() - s.m_counter);
|
TORRENT_ASSERT(m_total_counter < (std::numeric_limits<std::int64_t>::max)() - s.m_counter);
|
||||||
m_total_counter += s.m_counter;
|
m_total_counter += s.m_counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,26 +64,26 @@ namespace libtorrent
|
||||||
{
|
{
|
||||||
TORRENT_ASSERT(count >= 0);
|
TORRENT_ASSERT(count >= 0);
|
||||||
|
|
||||||
TORRENT_ASSERT(m_counter < (std::numeric_limits<std::uint32_t>::max)() - count);
|
TORRENT_ASSERT(m_counter < (std::numeric_limits<std::int32_t>::max)() - count);
|
||||||
m_counter += count;
|
m_counter += count;
|
||||||
TORRENT_ASSERT(m_total_counter < (std::numeric_limits<std::uint64_t>::max)() - count);
|
TORRENT_ASSERT(m_total_counter < (std::numeric_limits<std::int64_t>::max)() - count);
|
||||||
m_total_counter += count;
|
m_total_counter += count;
|
||||||
}
|
}
|
||||||
|
|
||||||
// should be called once every second
|
// should be called once every second
|
||||||
void second_tick(int tick_interval_ms);
|
void second_tick(int tick_interval_ms);
|
||||||
int rate() const { return m_5_sec_average; }
|
std::int32_t rate() const { return m_5_sec_average; }
|
||||||
int low_pass_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; }
|
std::int64_t total() const { return m_total_counter; }
|
||||||
|
|
||||||
void offset(std::int64_t c)
|
void offset(std::int64_t c)
|
||||||
{
|
{
|
||||||
TORRENT_ASSERT(m_total_counter < (std::numeric_limits<std::uint64_t>::max)() - c);
|
TORRENT_ASSERT(m_total_counter < (std::numeric_limits<std::int64_t>::max)() - c);
|
||||||
m_total_counter += c;
|
m_total_counter += c;
|
||||||
}
|
}
|
||||||
|
|
||||||
int counter() const { return m_counter; }
|
std::int32_t counter() const { return m_counter; }
|
||||||
|
|
||||||
void clear()
|
void clear()
|
||||||
{
|
{
|
||||||
|
@ -98,18 +95,17 @@ namespace libtorrent
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// total counters
|
// total counters
|
||||||
std::uint64_t m_total_counter;
|
std::int64_t m_total_counter;
|
||||||
|
|
||||||
// the accumulator for this second.
|
// the accumulator for this second.
|
||||||
std::uint32_t m_counter;
|
std::int32_t m_counter;
|
||||||
|
|
||||||
// sliding average
|
// sliding average
|
||||||
std::uint32_t m_5_sec_average;
|
std::int32_t m_5_sec_average;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TORRENT_EXTRA_EXPORT stat
|
class TORRENT_EXTRA_EXPORT stat
|
||||||
{
|
{
|
||||||
friend class invariant_access;
|
|
||||||
public:
|
public:
|
||||||
void operator+=(const stat& s)
|
void operator+=(const stat& s)
|
||||||
{
|
{
|
||||||
|
@ -285,4 +281,3 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // TORRENT_STAT_HPP_INCLUDED
|
#endif // TORRENT_STAT_HPP_INCLUDED
|
||||||
|
|
||||||
|
|
|
@ -381,7 +381,7 @@ namespace libtorrent
|
||||||
, peer_request p);
|
, peer_request p);
|
||||||
void on_disk_tick_done(disk_io_job const* j);
|
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
|
struct read_piece_struct
|
||||||
{
|
{
|
||||||
boost::shared_array<char> piece_data;
|
boost::shared_array<char> piece_data;
|
||||||
|
@ -566,9 +566,9 @@ namespace libtorrent
|
||||||
peer_class_t peer_class() const { return peer_class_t(m_peer_class); }
|
peer_class_t peer_class() const { return peer_class_t(m_peer_class); }
|
||||||
|
|
||||||
void set_max_uploads(int limit, bool state_update = true);
|
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);
|
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
|
// PEER MANAGEMENT
|
||||||
|
@ -1615,7 +1615,7 @@ namespace libtorrent
|
||||||
|
|
||||||
// progress parts per million (the number of
|
// progress parts per million (the number of
|
||||||
// millionths of completeness)
|
// millionths of completeness)
|
||||||
unsigned int m_progress_ppm:20;
|
std::uint32_t m_progress_ppm:20;
|
||||||
|
|
||||||
#if TORRENT_USE_ASSERTS
|
#if TORRENT_USE_ASSERTS
|
||||||
// set to true when torrent is start()ed. It may only be started once
|
// set to true when torrent is start()ed. It may only be started once
|
||||||
|
|
|
@ -143,7 +143,7 @@ namespace libtorrent
|
||||||
private:
|
private:
|
||||||
#if TORRENT_USE_IPV6
|
#if TORRENT_USE_IPV6
|
||||||
// the type of the addr union
|
// the type of the addr union
|
||||||
unsigned is_v6_addr:1;
|
bool is_v6_addr:1;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -605,7 +605,7 @@ namespace libtorrent
|
||||||
sha1_hash m_info_hash;
|
sha1_hash m_info_hash;
|
||||||
|
|
||||||
// the number of bytes in m_info_section
|
// 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
|
// the index to the first leaf. This is where the hash for the
|
||||||
// first piece is stored
|
// first piece is stored
|
||||||
|
|
|
@ -30,20 +30,16 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <numeric>
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
#include "libtorrent/stat.hpp"
|
#include "libtorrent/stat.hpp"
|
||||||
|
|
||||||
namespace libtorrent {
|
namespace libtorrent {
|
||||||
|
|
||||||
void stat_channel::second_tick(int tick_interval_ms)
|
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);
|
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;
|
m_counter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1088,7 +1088,7 @@ namespace libtorrent
|
||||||
m_info_section.reset(new char[m_info_section_size]);
|
m_info_section.reset(new char[m_info_section_size]);
|
||||||
std::memcpy(m_info_section.get(), section.data(), m_info_section_size);
|
std::memcpy(m_info_section.get(), section.data(), m_info_section_size);
|
||||||
TORRENT_ASSERT(section[0] == 'd');
|
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
|
// when translating a pointer that points into the 'info' tree's
|
||||||
// backing buffer, into a pointer to our copy of the info section,
|
// backing buffer, into a pointer to our copy of the info section,
|
||||||
|
|
Loading…
Reference in New Issue