fixing sign-conversion warnings, part 7 (#1604)

fixing sign-conversion warnings, part 7
This commit is contained in:
Alden Torres 2017-01-24 01:35:17 -05:00 committed by Arvid Norberg
parent 4896a5ed3c
commit 4ddd4b72c6
4 changed files with 35 additions and 27 deletions

View File

@ -49,6 +49,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/copy_ptr.hpp"
#include "libtorrent/sha1_hash.hpp"
#include "libtorrent/file_storage.hpp"
#include "libtorrent/aux_/vector.hpp"
#if TORRENT_COMPLETE_TYPES_REQUIRED
#include "libtorrent/announce_entry.hpp"
@ -432,7 +433,7 @@ namespace libtorrent
int const idx = static_cast<int>(index);
if (is_merkle_torrent())
{
TORRENT_ASSERT(idx < int(m_merkle_tree.size() - m_merkle_first_leaf));
TORRENT_ASSERT(idx < m_merkle_tree.end_index() - m_merkle_first_leaf);
return m_merkle_tree[m_merkle_first_leaf + idx].data();
}
else
@ -556,7 +557,7 @@ namespace libtorrent
copy_ptr<const file_storage> m_orig_files;
// the urls to the trackers
std::vector<announce_entry> m_urls;
aux::vector<announce_entry> m_urls;
std::vector<web_seed_entry> m_web_seeds;
// dht nodes to add to the routing table/bootstrap from
std::vector<std::pair<std::string, int>> m_nodes;
@ -585,7 +586,7 @@ namespace libtorrent
// if this is a merkle torrent, this is the merkle
// tree. It has space for merkle_num_nodes(merkle_num_leafs(num_pieces))
// hashes
std::vector<sha1_hash> m_merkle_tree;
aux::vector<sha1_hash> m_merkle_tree;
// this is a copy of the info section from the torrent.
// it use maintained in this flat format in order to
@ -612,7 +613,7 @@ namespace libtorrent
// if a creation date is found in the torrent file
// this will be set to that, otherwise it'll be
// 1970, Jan 1
time_t m_creation_date = 0;
std::time_t m_creation_date = 0;
// the hash that identifies this torrent
sha1_hash m_info_hash;
@ -622,7 +623,7 @@ namespace libtorrent
// the index to the first leaf. This is where the hash for the
// first piece is stored
std::uint32_t m_merkle_first_leaf = 0;
std::int32_t m_merkle_first_leaf = 0;
enum flags_t : std::uint8_t
{

View File

@ -1713,7 +1713,7 @@ namespace libtorrent {
std::array<std::int64_t, counters::num_counters> arr;
for (int i = 0; i < counters::num_counters; ++i)
arr[i] = cnt[i];
arr[std::size_t(i)] = cnt[i];
return arr;
}
@ -1952,11 +1952,12 @@ namespace libtorrent {
}
#endif
std::vector<tcp::endpoint> dht_get_peers_reply_alert::peers() const {
std::vector<tcp::endpoint> peers(m_num_peers);
std::size_t const num_peers = aux::numeric_cast<std::size_t>(m_num_peers);
std::vector<tcp::endpoint> peers(num_peers);
const char *ptr = m_alloc.get().ptr(m_peers_idx);
for (int i = 0; i < m_num_peers; i++) {
std::size_t size = detail::read_uint8(ptr);
for (std::size_t i = 0; i < num_peers; i++) {
std::size_t const size = detail::read_uint8(ptr);
std::memcpy(peers[i].data(), ptr, size);
ptr += size;
}
@ -1994,7 +1995,8 @@ namespace libtorrent {
char msg[1050];
std::snprintf(msg, sizeof(msg), "DHT direct response (address=%s) [ %s ]"
, endpoint.address().to_string().c_str()
, m_response_size ? std::string(m_alloc.get().ptr(m_response_idx), m_response_size).c_str() : "");
, m_response_size ? std::string(m_alloc.get().ptr(m_response_idx)
, aux::numeric_cast<std::size_t>(m_response_size)).c_str() : "");
return msg;
}
@ -2016,7 +2018,7 @@ namespace libtorrent {
: peer_alert(alloc, h, ep, peer_id)
, picker_flags(flags)
, m_array_idx(alloc.copy_buffer({reinterpret_cast<char const*>(blocks)
, num_blocks * sizeof(piece_block)}))
, aux::numeric_cast<std::size_t>(num_blocks) * sizeof(piece_block)}))
, m_num_blocks(num_blocks)
{}
@ -2024,10 +2026,11 @@ namespace libtorrent {
{
// we need to copy this array to make sure the structures are properly
// aligned, not just to have a nice API
std::vector<piece_block> ret(m_num_blocks);
std::size_t const num_blocks = aux::numeric_cast<std::size_t>(m_num_blocks);
std::vector<piece_block> ret(num_blocks);
char const* start = m_alloc.get().ptr(m_array_idx);
std::memcpy(ret.data(), start, m_num_blocks * sizeof(piece_block));
std::memcpy(ret.data(), start, num_blocks * sizeof(piece_block));
return ret;
}

View File

@ -32,6 +32,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/bdecode.hpp"
#include "libtorrent/alloca.hpp"
#include "libtorrent/aux_/vector.hpp" // for numeric_cast
#include <limits>
#include <cstring> // for memset
#include <cstdio> // for snprintf
@ -101,7 +102,7 @@ namespace libtorrent
struct stack_frame
{
explicit stack_frame(int const t): token(t), state(0) {}
explicit stack_frame(int const t): token(std::uint32_t(t)), state(0) {}
// this is an index into m_tokens
std::uint32_t token:31;
// this is used for dictionaries to indicate whether we're
@ -573,7 +574,8 @@ namespace libtorrent
{
TORRENT_ASSERT(type() == string_t);
bdecode_token const& t = m_root_tokens[m_token_idx];
std::size_t const size = m_root_tokens[m_token_idx + 1].offset - t.offset - t.start_offset();
std::size_t const size = m_root_tokens[m_token_idx + 1].offset - t.offset
- aux::numeric_cast<std::size_t>(t.start_offset());
TORRENT_ASSERT(t.type == bdecode_token::string);
return string_view(m_buffer + t.offset + t.start_offset(), size);
@ -596,7 +598,7 @@ namespace libtorrent
}
void bdecode_node::reserve(int tokens)
{ m_tokens.reserve(tokens); }
{ m_tokens.reserve(aux::numeric_cast<std::size_t>(tokens)); }
void bdecode_node::swap(bdecode_node& n)
{
@ -637,7 +639,7 @@ namespace libtorrent
} TORRENT_WHILE_0
int bdecode(char const* start, char const* end, bdecode_node& ret
, error_code& ec, int* error_pos, int depth_limit, int token_limit)
, error_code& ec, int* error_pos, int const depth_limit, int token_limit)
{
ec.clear();
ret.clear();
@ -651,7 +653,7 @@ namespace libtorrent
// this is the stack of bdecode_token indices, into m_tokens.
// sp is the stack pointer, as index into the array, stack
int sp = 0;
std::size_t sp = 0;
TORRENT_ALLOCA(stack, stack_frame, depth_limit);
char const* const orig_start = start;
@ -663,7 +665,7 @@ namespace libtorrent
{
if (start >= end) TORRENT_FAIL_BDECODE(bdecode_errors::unexpected_eof);
if (sp >= depth_limit)
if (sp >= aux::numeric_cast<std::size_t>(depth_limit))
TORRENT_FAIL_BDECODE(bdecode_errors::depth_exceeded);
--token_limit;
@ -673,7 +675,7 @@ namespace libtorrent
// look for a new token
char const t = *start;
int const current_frame = sp;
std::size_t const current_frame = sp;
// if we're currently parsing a dictionary, assert that
// every other node is a string.
@ -753,12 +755,13 @@ namespace libtorrent
int const top = stack[sp - 1].token;
// subtract the token's own index, since this is a relative
// offset
if (ret.m_tokens.size() - top > bdecode_token::max_next_item)
if (int(ret.m_tokens.size()) - top > bdecode_token::max_next_item)
TORRENT_FAIL_BDECODE(bdecode_errors::limit_exceeded);
ret.m_tokens[top].next_item = std::uint32_t(ret.m_tokens.size() - top);
ret.m_tokens[std::size_t(top)].next_item = std::uint32_t(int(ret.m_tokens.size()) - top);
// and pop it from the stack.
TORRENT_ASSERT(sp > 0);
--sp;
++start;
break;
@ -832,8 +835,8 @@ done:
}
int const top = stack[sp].token;
TORRENT_ASSERT(ret.m_tokens.size() - top <= bdecode_token::max_next_item);
ret.m_tokens[top].next_item = std::uint32_t(ret.m_tokens.size() - top);
TORRENT_ASSERT(int(ret.m_tokens.size()) - top <= bdecode_token::max_next_item);
ret.m_tokens[std::size_t(top)].next_item = std::uint32_t(int(ret.m_tokens.size()) - top);
ret.m_tokens.push_back({start - orig_start, 1, bdecode_token::end});
}
@ -922,7 +925,7 @@ done:
bool printable = true;
for (int i = 0; i < len; ++i)
{
char const c = str[i];
char const c = str[std::size_t(i)];
if (c >= 32 && c < 127) continue;
printable = false;
break;
@ -937,7 +940,7 @@ done:
ret.append(str.data() + len - 14, 14);
}
else
ret.append(str.data(), len);
ret.append(str.data(), std::size_t(len));
ret += "'";
return;
}

View File

@ -42,6 +42,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/socket_io.hpp" // for print_address
#include "libtorrent/debug.hpp"
#include "libtorrent/hex.hpp" // to_hex, from_hex
#include "libtorrent/aux_/vector.hpp" // for numeric_cast
using namespace std::placeholders;
@ -53,7 +54,7 @@ int render_lsd_packet(char* dst, int const len, int const listen_port
, char const* info_hash_hex, int const cookie, char const* host)
{
TORRENT_ASSERT(len > 0);
return std::snprintf(dst, len,
return std::snprintf(dst, aux::numeric_cast<std::size_t>(len),
"BT-SEARCH * HTTP/1.1\r\n"
"Host: %s:6771\r\n"
"Port: %d\r\n"