fixing sign-conversion warnings, part 19

This commit is contained in:
Alden Torres 2017-02-21 10:12:18 -05:00 committed by Arvid Norberg
parent 267cab6822
commit 23edbfbee8
3 changed files with 28 additions and 29 deletions

View File

@ -52,8 +52,8 @@ namespace libtorrent
{ {
torrent_peer(std::uint16_t port, bool connectable, int src); torrent_peer(std::uint16_t port, bool connectable, int src);
std::uint64_t total_download() const; std::int64_t total_download() const;
std::uint64_t total_upload() const; std::int64_t total_upload() const;
std::uint32_t rank(external_ip const& external, int external_port) const; std::uint32_t rank(external_ip const& external, int external_port) const;

View File

@ -230,9 +230,9 @@ namespace libtorrent
TORRENT_ASSERT(m_type == dict_t || m_type == list_t); TORRENT_ASSERT(m_type == dict_t || m_type == list_t);
if (m_data.list == nullptr) return 0; if (m_data.list == nullptr) return 0;
if (m_type == dict_t) if (m_type == dict_t)
return m_data.dict[0].val.m_len; return int(m_data.dict[0].val.m_len);
else else
return m_data.list[0].m_len; return int(m_data.list[0].m_len);
} }
std::int64_t lazy_entry::int_value() const std::int64_t lazy_entry::int_value() const
@ -255,14 +255,14 @@ namespace libtorrent
TORRENT_ASSERT(int(m_size) <= this->capacity()); TORRENT_ASSERT(int(m_size) <= this->capacity());
if (m_data.dict == nullptr) if (m_data.dict == nullptr)
{ {
int capacity = lazy_entry_dict_init; int const capacity = lazy_entry_dict_init;
m_data.dict = new (std::nothrow) lazy_dict_entry[capacity + 1]; m_data.dict = new (std::nothrow) lazy_dict_entry[capacity + 1];
if (m_data.dict == nullptr) return nullptr; if (m_data.dict == nullptr) return nullptr;
m_data.dict[0].val.m_len = capacity; m_data.dict[0].val.m_len = std::uint32_t(capacity);
} }
else if (int(m_size) == this->capacity()) else if (int(m_size) == this->capacity())
{ {
int capacity = this->capacity() * lazy_entry_grow_factor / 100; int const capacity = this->capacity() * lazy_entry_grow_factor / 100;
lazy_dict_entry* tmp = new (std::nothrow) lazy_dict_entry[capacity + 1]; lazy_dict_entry* tmp = new (std::nothrow) lazy_dict_entry[capacity + 1];
if (tmp == nullptr) return nullptr; if (tmp == nullptr) return nullptr;
std::memcpy(tmp, m_data.dict, sizeof(lazy_dict_entry) * (m_size + 1)); std::memcpy(tmp, m_data.dict, sizeof(lazy_dict_entry) * (m_size + 1));
@ -270,7 +270,7 @@ namespace libtorrent
delete[] m_data.dict; delete[] m_data.dict;
m_data.dict = tmp; m_data.dict = tmp;
m_data.dict[0].val.m_len = capacity; m_data.dict[0].val.m_len = std::uint32_t(capacity);
} }
TORRENT_ASSERT(int(m_size) < this->capacity()); TORRENT_ASSERT(int(m_size) < this->capacity());
@ -303,9 +303,10 @@ namespace libtorrent
void lazy_entry::construct_string(char const* start, int const length) void lazy_entry::construct_string(char const* start, int const length)
{ {
TORRENT_ASSERT(m_type == none_t); TORRENT_ASSERT(m_type == none_t);
TORRENT_ASSERT(length >= 0);
m_type = string_t; m_type = string_t;
m_data.start = start; m_data.start = start;
m_size = length; m_size = std::uint32_t(length);
m_begin = start - 1 - num_digits(length); m_begin = start - 1 - num_digits(length);
m_len = std::uint32_t(start - m_begin + length); m_len = std::uint32_t(start - m_begin + length);
} }
@ -333,7 +334,8 @@ namespace libtorrent
TORRENT_ASSERT(m_type == dict_t); TORRENT_ASSERT(m_type == dict_t);
TORRENT_ASSERT(i < int(m_size)); TORRENT_ASSERT(i < int(m_size));
lazy_dict_entry const& e = m_data.dict[i + 1]; lazy_dict_entry const& e = m_data.dict[i + 1];
return std::make_pair(std::string(e.name, e.val.m_begin - e.name), &e.val); TORRENT_ASSERT(e.val.m_begin >= e.name);
return std::make_pair(std::string(e.name, std::size_t(e.val.m_begin - e.name)), &e.val);
} }
std::string lazy_entry::dict_find_string_value(char const* name) const std::string lazy_entry::dict_find_string_value(char const* name) const
@ -424,14 +426,14 @@ namespace libtorrent
TORRENT_ASSERT(int(m_size) <= this->capacity()); TORRENT_ASSERT(int(m_size) <= this->capacity());
if (m_data.start == nullptr) if (m_data.start == nullptr)
{ {
int capacity = lazy_entry_list_init; int const capacity = lazy_entry_list_init;
m_data.list = new (std::nothrow) lazy_entry[capacity + 1]; m_data.list = new (std::nothrow) lazy_entry[capacity + 1];
if (m_data.list == nullptr) return nullptr; if (m_data.list == nullptr) return nullptr;
m_data.list[0].m_len = capacity; m_data.list[0].m_len = std::uint32_t(capacity);
} }
else if (int(m_size) == this->capacity()) else if (int(m_size) == this->capacity())
{ {
int capacity = this->capacity() * lazy_entry_grow_factor / 100; int const capacity = this->capacity() * lazy_entry_grow_factor / 100;
lazy_entry* tmp = new (std::nothrow) lazy_entry[capacity + 1]; lazy_entry* tmp = new (std::nothrow) lazy_entry[capacity + 1];
if (tmp == nullptr) return nullptr; if (tmp == nullptr) return nullptr;
std::memcpy(tmp, m_data.list, sizeof(lazy_entry) * (m_size + 1)); std::memcpy(tmp, m_data.list, sizeof(lazy_entry) * (m_size + 1));
@ -439,7 +441,7 @@ namespace libtorrent
delete[] m_data.list; delete[] m_data.list;
m_data.list = tmp; m_data.list = tmp;
m_data.list[0].m_len = capacity; m_data.list[0].m_len = std::uint32_t(capacity);
} }
TORRENT_ASSERT(int(m_size) < this->capacity()); TORRENT_ASSERT(int(m_size) < this->capacity());
@ -561,6 +563,7 @@ namespace libtorrent
void print_string(std::string& ret, char const* str, int const len, bool single_line) void print_string(std::string& ret, char const* str, int const len, bool single_line)
{ {
TORRENT_ASSERT(len >= 0);
bool printable = true; bool printable = true;
for (int i = 0; i < len; ++i) for (int i = 0; i < len; ++i)
{ {
@ -579,7 +582,7 @@ namespace libtorrent
ret.append(str + len - 14, 14); ret.append(str + len - 14, 14);
} }
else else
ret.append(str, len); ret.append(str, std::size_t(len));
ret += "'"; ret += "'";
return; return;
} }

View File

@ -85,10 +85,10 @@ namespace libtorrent
swap(e1, e2); swap(e1, e2);
std::uint32_t p; std::uint32_t p;
#if defined BOOST_BIG_ENDIAN #if defined BOOST_BIG_ENDIAN
p = e1.port() << 16; p = std::uint32_t(e1.port() << 16);
p |= e2.port(); p |= e2.port();
#elif defined BOOST_LITTLE_ENDIAN #elif defined BOOST_LITTLE_ENDIAN
p = aux::host_to_network(e2.port()) << 16; p = std::uint32_t(aux::host_to_network(e2.port()) << 16);
p |= aux::host_to_network(e1.port()); p |= aux::host_to_network(e1.port());
#else #else
#error unsupported endianness #error unsupported endianness
@ -141,7 +141,7 @@ namespace libtorrent
return ret; return ret;
} }
torrent_peer::torrent_peer(std::uint16_t port_, bool conn, int src) torrent_peer::torrent_peer(std::uint16_t port_, bool conn, int const src)
: prev_amount_upload(0) : prev_amount_upload(0)
, prev_amount_download(0) , prev_amount_download(0)
, connection(nullptr) , connection(nullptr)
@ -156,7 +156,7 @@ namespace libtorrent
, seed(false) , seed(false)
, fast_reconnects(0) , fast_reconnects(0)
, trust_points(0) , trust_points(0)
, source(src) , source(aux::numeric_cast<std::uint8_t>(src))
#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) #if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
// assume no support in order to // assume no support in order to
// prefer opening non-encrypted // prefer opening non-encrypted
@ -179,9 +179,7 @@ namespace libtorrent
#if TORRENT_USE_ASSERTS #if TORRENT_USE_ASSERTS
, in_use(false) , in_use(false)
#endif #endif
{ {}
TORRENT_ASSERT((src & 0xff) == src);
}
std::uint32_t torrent_peer::rank(external_ip const& external, int external_port) const std::uint32_t torrent_peer::rank(external_ip const& external, int external_port) const
{ {
@ -204,7 +202,7 @@ namespace libtorrent
} }
#endif #endif
std::uint64_t torrent_peer::total_download() const std::int64_t torrent_peer::total_download() const
{ {
if (connection != nullptr) if (connection != nullptr)
{ {
@ -213,11 +211,11 @@ namespace libtorrent
} }
else else
{ {
return std::uint64_t(prev_amount_download) << 10; return std::int64_t(prev_amount_download) << 10;
} }
} }
std::uint64_t torrent_peer::total_upload() const std::int64_t torrent_peer::total_upload() const
{ {
if (connection != nullptr) if (connection != nullptr)
{ {
@ -226,13 +224,11 @@ namespace libtorrent
} }
else else
{ {
return std::uint64_t(prev_amount_upload) << 10; return std::int64_t(prev_amount_upload) << 10;
} }
} }
ipv4_peer::ipv4_peer( ipv4_peer::ipv4_peer(tcp::endpoint const& ep, bool c, int src)
tcp::endpoint const& ep, bool c, int src
)
: torrent_peer(ep.port(), c, src) : torrent_peer(ep.port(), c, src)
, addr(ep.address().to_v4()) , addr(ep.address().to_v4())
{ {