more fixes of integral type conversion warnings

This commit is contained in:
Alden Torres 2016-11-21 10:08:26 -05:00 committed by Arvid Norberg
parent 84e0362180
commit 86251adb1b
23 changed files with 58 additions and 60 deletions

View File

@ -105,7 +105,7 @@ namespace libtorrent
, boost::asio::ip::tcp const& protocol
, char const* device_name, int port, error_code& ec)
{
tcp::endpoint bind_ep(address_v4::any(), port);
tcp::endpoint bind_ep(address_v4::any(), std::uint16_t(port));
address ip = address::from_string(device_name, ec);
if (!ec)

View File

@ -335,7 +335,7 @@ namespace libtorrent
int picker_options() const;
void prefer_contiguous_blocks(int num)
{ m_prefer_contiguous_blocks = (std::min)(num, 255); }
{ m_prefer_contiguous_blocks = std::uint8_t((std::min)(num, 255)); }
bool request_large_blocks() const
{ return m_request_large_blocks; }

View File

@ -39,7 +39,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/error_code.hpp"
#include "libtorrent/bdecode.hpp"
#include "libtorrent/bencode.hpp"
#include "libtorrent/peer_id.hpp" // for sha1_hash
#include "libtorrent/sha1_hash.hpp"
#include <string>
namespace libtorrent
@ -75,7 +75,7 @@ namespace libtorrent
if (a.is_v4())
{
#endif
write_uint32(a.to_v4().to_ulong(), out);
write_uint32(std::uint32_t(a.to_v4().to_ulong()), out);
#if TORRENT_USE_IPV6
}
else if (a.is_v6())
@ -115,7 +115,7 @@ namespace libtorrent
Endpoint read_v4_endpoint(InIt&& in)
{
address addr = read_v4_address(in);
int port = read_uint16(in);
std::uint16_t port = read_uint16(in);
return Endpoint(addr, port);
}
@ -124,7 +124,7 @@ namespace libtorrent
Endpoint read_v6_endpoint(InIt&& in)
{
address addr = read_v6_address(in);
int port = read_uint16(in);
std::uint16_t port = read_uint16(in);
return Endpoint(addr, port);
}
#endif
@ -153,4 +153,3 @@ namespace libtorrent
}
#endif

View File

@ -633,7 +633,7 @@ namespace libtorrent
#define TORRENT_FAIL_BDECODE(code) do { \
ec = code; \
if (error_pos) *error_pos = start - orig_start; \
if (error_pos) *error_pos = int(start - orig_start); \
goto done; \
} TORRENT_WHILE_0
@ -720,7 +720,7 @@ namespace libtorrent
{
// in order to gracefully terminate the tree,
// make sure the end of the previous token is set correctly
if (error_pos) *error_pos = start - orig_start;
if (error_pos) *error_pos = int(start - orig_start);
error_pos = nullptr;
start = int_start;
TORRENT_FAIL_BDECODE(e);
@ -799,7 +799,7 @@ namespace libtorrent
TORRENT_FAIL_BDECODE(bdecode_errors::limit_exceeded);
ret.m_tokens.push_back(bdecode_token(str_start - orig_start
, 1, bdecode_token::string, start - str_start));
, 1, bdecode_token::string, std::uint8_t(start - str_start)));
start += len;
break;
}

View File

@ -75,7 +75,7 @@ namespace
std::memcpy(ptr, v.data(), std::min(v.size(), left));
ptr += std::min(v.size(), left);
TORRENT_ASSERT((ptr - out.data()) <= int(out.size()));
return ptr - out.data();
return int(ptr - out.data());
}
}

View File

@ -764,7 +764,7 @@ entry write_nodes_entry(std::vector<node_entry> const& nodes)
for (auto const& n : nodes)
{
std::copy(n.id.begin(), n.id.end(), out);
detail::write_endpoint(udp::endpoint(n.addr(), n.port()), out);
detail::write_endpoint(udp::endpoint(n.addr(), std::uint16_t(n.port())), out);
}
return r;
}
@ -940,7 +940,7 @@ void node::incoming_request(msg const& m, entry& e)
// the table get a chance to add it.
m_table.node_seen(id, m.addr, 0xffff);
tcp::endpoint addr = tcp::endpoint(m.addr.address(), port);
tcp::endpoint addr = tcp::endpoint(m.addr.address(), std::uint16_t(port));
string_view name = msg_keys[3] ? msg_keys[3].string_value() : string_view();
bool seed = msg_keys[4] && msg_keys[4].int_value();

View File

@ -332,7 +332,7 @@ bool compare_ip_cidr(address const& lhs, address const& rhs)
// if IPv4 addresses is in the same /24, they're too close and we won't
// trust the second one
std::uint32_t const mask
= lhs.to_v4().to_ulong() ^ rhs.to_v4().to_ulong();
= std::uint32_t(lhs.to_v4().to_ulong() ^ rhs.to_v4().to_ulong());
return mask <= 0x000000ff;
}
}
@ -368,7 +368,7 @@ void routing_table::fill_from_replacements(table_t::iterator bucket)
{
bucket_t& b = bucket->live_nodes;
bucket_t& rb = bucket->replacements;
int const bucket_size = bucket_limit(std::distance(m_buckets.begin(), bucket));
int const bucket_size = bucket_limit(int(std::distance(m_buckets.begin(), bucket)));
if (int(b.size()) >= bucket_size) return;
@ -396,7 +396,7 @@ void routing_table::remove_node(node_entry* n
&& n >= &bucket->replacements[0]
&& n < &bucket->replacements[0] + bucket->replacements.size())
{
int idx = n - &bucket->replacements[0];
std::ptrdiff_t idx = n - &bucket->replacements[0];
TORRENT_ASSERT(m_ips.count(n->addr()) > 0);
m_ips.erase(n->addr());
bucket->replacements.erase(bucket->replacements.begin() + idx);
@ -406,7 +406,7 @@ void routing_table::remove_node(node_entry* n
&& n >= &bucket->live_nodes[0]
&& n < &bucket->live_nodes[0] + bucket->live_nodes.size())
{
int idx = n - &bucket->live_nodes[0];
std::ptrdiff_t idx = n - &bucket->live_nodes[0];
TORRENT_ASSERT(m_ips.count(n->addr()) > 0);
m_ips.erase(n->addr());
bucket->live_nodes.erase(bucket->live_nodes.begin() + idx);
@ -563,7 +563,7 @@ routing_table::add_node_status_t routing_table::add_node_impl(node_entry e)
table_t::iterator i = find_bucket(e.id);
bucket_t& b = i->live_nodes;
bucket_t& rb = i->replacements;
int const bucket_index = std::distance(m_buckets.begin(), i);
int const bucket_index = int(std::distance(m_buckets.begin(), i));
// compare against the max size of the next bucket. Otherwise we may wait too
// long to split, and lose nodes (in the case where lower-numbered buckets
// are larger)
@ -1111,7 +1111,7 @@ void routing_table::find_node(node_id const& target
if (count == 0) count = m_bucket_size;
table_t::iterator i = find_bucket(target);
int const bucket_index = std::distance(m_buckets.begin(), i);
int const bucket_index = int(std::distance(m_buckets.begin(), i));
int const bucket_size_limit = bucket_limit(bucket_index);
l.reserve(bucket_size_limit);

View File

@ -450,7 +450,7 @@ bool rpc_manager::invoke(entry& e, udp::endpoint const& target_addr
std::string transaction_id;
transaction_id.resize(2);
char* out = &transaction_id[0];
int tid = random(0x7fff);
std::uint16_t tid = std::uint16_t(random(0x7fff));
detail::write_uint16(tid, out);
e["t"] = transaction_id;

View File

@ -525,7 +525,7 @@ void traversal_algorithm::add_router_entries()
void traversal_algorithm::init()
{
m_branch_factor = m_node.branch_factor();
m_branch_factor = std::int16_t(m_node.branch_factor());
m_node.add_traversal_algorithm(this);
}

View File

@ -66,7 +66,7 @@ namespace libtorrent
}
stack.pop_back();
}
if (error_pos) *error_pos = start - orig_start;
if (error_pos) *error_pos = int(start - orig_start);
return -1;
}
@ -188,7 +188,7 @@ namespace libtorrent
{
char const* int_start = start;
start = find_char(start, end, 'e');
top->construct_int(int_start, start - int_start);
top->construct_int(int_start, int(start - int_start));
if (start == end) TORRENT_FAIL_BDECODE(bdecode_errors::unexpected_eof);
TORRENT_ASSERT(*start == 'e');
++start;
@ -307,7 +307,7 @@ namespace libtorrent
m_data.start = start;
m_size = length;
m_begin = start - 1 - num_digits(length);
m_len = start - m_begin + length;
m_len = std::uint32_t(start - m_begin + length);
}
namespace
@ -398,8 +398,8 @@ namespace libtorrent
TORRENT_ASSERT(m_type == dict_t);
for (int i = 0; i < int(m_size); ++i)
{
lazy_dict_entry& e = m_data.dict[i+1];
if (string_equal(name, e.name, e.val.m_begin - e.name))
lazy_dict_entry& e = m_data.dict[i + 1];
if (string_equal(name, e.name, int(e.val.m_begin - e.name)))
return &e.val;
}
return nullptr;

View File

@ -279,7 +279,7 @@ void lsd::on_announce(udp::endpoint const& from, char const* buf
}
#endif
// we got an announce, pass it on through the callback
m_callback.on_lsd_peer(tcp::endpoint(from.address(), port), ih);
m_callback.on_lsd_peer(tcp::endpoint(from.address(), std::uint16_t(port)), ih);
}
}
}

View File

@ -781,7 +781,7 @@ namespace libtorrent
i->connection = &c;
TORRENT_ASSERT(i->connection);
if (!c.fast_reconnect())
i->last_connected = session_time;
i->last_connected = std::uint16_t(session_time);
// this cannot be a connect candidate anymore, since i->connection is set
TORRENT_ASSERT(!is_connect_candidate(*i));
@ -789,7 +789,7 @@ namespace libtorrent
return true;
}
bool peer_list::update_peer_port(int port, torrent_peer* p, int src, torrent_state* state)
bool peer_list::update_peer_port(int const port, torrent_peer* p, int src, torrent_state* state)
{
TORRENT_ASSERT(p != nullptr);
TORRENT_ASSERT(p->connection);
@ -802,7 +802,7 @@ namespace libtorrent
if (state->allow_multiple_connections_per_ip)
{
tcp::endpoint remote(p->address(), port);
tcp::endpoint remote(p->address(), std::uint16_t(port));
std::pair<iterator, iterator> range = find_peers(remote.address());
iterator i = std::find_if(range.first, range.second
, match_peer_endpoint(remote));
@ -849,7 +849,7 @@ namespace libtorrent
#endif
bool const was_conn_cand = is_connect_candidate(*p);
p->port = port;
p->port = std::uint16_t(port);
p->source |= src;
p->connectable = true;
@ -1215,7 +1215,7 @@ namespace libtorrent
// update the timestamp, and it will remain
// the time when we initiated the connection.
if (!c.fast_reconnect())
p->last_connected = session_time;
p->last_connected = std::uint16_t(session_time);
if (c.failed())
{

View File

@ -811,7 +811,7 @@ namespace libtorrent
if (net_interface == nullptr || strlen(net_interface) == 0)
net_interface = "0.0.0.0";
interfaces_str = print_endpoint(tcp::endpoint(address::from_string(net_interface, ec), port_range.first));
interfaces_str = print_endpoint(tcp::endpoint(address::from_string(net_interface, ec), std::uint16_t(port_range.first)));
if (ec) return;
p.set_str(settings_pack::listen_interfaces, interfaces_str);
@ -850,9 +850,9 @@ namespace libtorrent
pe_settings r;
r.prefer_rc4 = sett.get_bool(settings_pack::prefer_rc4);
r.out_enc_policy = sett.get_int(settings_pack::out_enc_policy);
r.in_enc_policy = sett.get_int(settings_pack::in_enc_policy);
r.allowed_enc_level = sett.get_int(settings_pack::allowed_enc_level);
r.out_enc_policy = std::uint8_t(sett.get_int(settings_pack::out_enc_policy));
r.in_enc_policy = std::uint8_t(sett.get_int(settings_pack::in_enc_policy));
r.allowed_enc_level = std::uint8_t(sett.get_int(settings_pack::allowed_enc_level));
return r;
}
#endif
@ -893,7 +893,7 @@ namespace libtorrent
proxy_settings ret;
settings_pack sett = get_settings();
ret.hostname = sett.get_str(settings_pack::i2p_hostname);
ret.port = sett.get_int(settings_pack::i2p_port);
ret.port = std::uint16_t(sett.get_int(settings_pack::i2p_port));
return ret;
}

View File

@ -141,7 +141,7 @@ namespace libtorrent
return ret;
}
ret.port(std::atoi(&*port_pos));
ret.port(std::uint16_t(std::atoi(&*port_pos)));
return ret;
}

View File

@ -301,7 +301,7 @@ namespace libtorrent
:(m_remote_endpoint.address().is_v4()?4:16)));
char* p = &m_buffer[0];
write_uint8(5, p); // SOCKS VERSION 5
write_uint8(m_command, p); // CONNECT/BIND command
write_uint8(std::uint8_t(m_command), p); // CONNECT/BIND command
write_uint8(0, p); // reserved
if (!m_dst_name.empty())
{
@ -333,7 +333,7 @@ namespace libtorrent
m_buffer.resize(m_user.size() + 9);
char* p = &m_buffer[0];
write_uint8(4, p); // SOCKS VERSION 4
write_uint8(m_command, p); // CONNECT/BIND command
write_uint8(std::uint8_t(m_command), p); // CONNECT/BIND command
write_uint16(m_remote_endpoint.port(), p);
write_uint32(m_remote_endpoint.address().to_v4().to_ulong(), p);
std::copy(m_user.begin(), m_user.end(), p);

View File

@ -197,7 +197,7 @@ namespace libtorrent
detail::write_uint64(offset, ptr);
detail::write_uint64(static_cast<std::uint64_t>(event_id++), ptr);
detail::write_uint32(fileid, ptr);
detail::write_uint8(flags, ptr);
detail::write_uint8(std::uint8_t(flags), ptr);
std::unique_lock<std::mutex> l(disk_access_mutex);
int const ret = int(fwrite(event, 1, sizeof(event), g_access_log));
@ -484,7 +484,7 @@ namespace libtorrent
*/
}
ec.ec.clear();
m_file_priority[i] = new_prio;
m_file_priority[i] = std::uint8_t(new_prio);
}
if (m_part_file) m_part_file->flush_metadata(ec.ec);
if (ec)

View File

@ -294,7 +294,7 @@ namespace libtorrent
e.fail_limit = 0;
e.source = announce_entry::source_magnet_link;
e.tier = tier;
e.tier = std::uint8_t(tier);
if (!find_tracker(e.url))
{
m_trackers.push_back(e);

View File

@ -555,7 +555,7 @@ namespace libtorrent
c = *s1++;
if (c == 0)
break;
ret = (ret * 33) ^ to_lower(c);
ret = (ret * 33) ^ to_lower(char(c));
}
return ret;
@ -1406,7 +1406,7 @@ namespace libtorrent
announce_entry e(tier.list_string_value_at(k).to_string());
e.trim();
if (e.url.empty()) continue;
e.tier = j;
e.tier = std::uint8_t(j);
e.fail_limit = 0;
e.source = announce_entry::source_torrent;
#if TORRENT_USE_I2P
@ -1540,7 +1540,7 @@ namespace libtorrent
if (i != m_urls.end()) return;
announce_entry e(url);
e.tier = tier;
e.tier = std::uint8_t(tier);
e.source = announce_entry::source_client;
m_urls.push_back(e);

View File

@ -188,7 +188,7 @@ namespace libtorrent
//TODO: how do we deal with our external address changing?
if (peer_rank == 0)
peer_rank = peer_priority(
tcp::endpoint(external.external_address(this->address()), external_port)
tcp::endpoint(external.external_address(this->address()), std::uint16_t(external_port))
, tcp::endpoint(this->address(), this->port));
return peer_rank;
}

View File

@ -254,7 +254,7 @@ void udp_socket::send_hostname(char const* hostname, int const port
// the overload that takes a hostname is really only supported when we're
// using a proxy
address target = address::from_string(hostname, ec);
if (!ec) send(udp::endpoint(target, port), p, ec, flags);
if (!ec) send(udp::endpoint(target, std::uint16_t(port)), p, ec, flags);
}
void udp_socket::send(udp::endpoint const& ep, span<char const> p
@ -329,10 +329,10 @@ void udp_socket::wrap(char const* hostname, int const port, span<char const> p
write_uint8(0, h); // fragment
write_uint8(3, h); // atyp
int const hostlen = (std::min)(int(strlen(hostname)), 255);
write_uint8(hostlen, h); // hostname len
memcpy(h, hostname, hostlen);
write_uint8(std::uint8_t(hostlen), h); // hostname len
std::memcpy(h, hostname, hostlen);
h += hostlen;
write_uint16(port, h);
write_uint16(std::uint16_t(port), h);
std::array<boost::asio::const_buffer, 2> iovec;
iovec[0] = boost::asio::const_buffer(header, h - header);

View File

@ -109,7 +109,7 @@ namespace libtorrent
|| settings.get_int(settings_pack::proxy_type) == settings_pack::socks5_pw))
{
m_hostname = hostname;
m_target.port(port);
m_target.port(std::uint16_t(port));
start_announce();
}
else
@ -213,7 +213,7 @@ namespace libtorrent
for (std::vector<address>::const_iterator i = addresses.begin()
, end(addresses.end()); i != end; ++i)
m_endpoints.push_back(tcp::endpoint(*i, port));
m_endpoints.push_back(tcp::endpoint(*i, std::uint16_t(port)));
if (tracker_req().filter)
{
@ -767,7 +767,7 @@ namespace libtorrent
request_string.resize(str_len);
aux::write_uint8(2, out);
aux::write_uint8(str_len, out);
aux::write_uint8(std::uint8_t(str_len), out);
aux::write_string(request_string, out);
}
@ -805,4 +805,3 @@ namespace libtorrent
}
}

View File

@ -272,9 +272,9 @@ namespace libtorrent { namespace
int len = bencode(p, e);
int total_size = 2 + len + metadata_piece_size;
namespace io = detail;
io::write_uint32(total_size, header);
io::write_uint32(std::uint32_t(total_size), header);
io::write_uint8(bt_peer_connection::msg_extended, header);
io::write_uint8(m_message_index, header);
io::write_uint8(std::uint8_t(m_message_index), header);
m_pc.send_buffer(msg, len + 6);
// TODO: we really need to increment the refcounter on the torrent

View File

@ -326,13 +326,13 @@ namespace libtorrent
std::uint16_t recv_id = 0;
if (m_new_connection != -1)
{
send_id = m_new_connection;
recv_id = m_new_connection + 1;
send_id = std::uint16_t(m_new_connection);
recv_id = std::uint16_t(m_new_connection + 1);
m_new_connection = -1;
}
else
{
send_id = random(0xffff);
send_id = std::uint16_t(random(0xffff));
recv_id = send_id - 1;
}
utp_socket_impl* impl = construct_utp_impl(recv_id, send_id, str, this);