fixing shorten-64-to-32 warnings, part 3

This commit is contained in:
Alden Torres 2016-12-06 08:24:01 -05:00 committed by Arvid Norberg
parent 4142dfe5eb
commit e1dcf82e2a
8 changed files with 68 additions and 67 deletions

View File

@ -155,7 +155,7 @@ namespace libtorrent
continue; continue;
} }
int current = i - m_peers.begin(); int current = int(i - m_peers.begin());
TORRENT_ASSERT(current >= 0); TORRENT_ASSERT(current >= 0);
TORRENT_ASSERT(m_peers.size() > 0); TORRENT_ASSERT(m_peers.size() > 0);
TORRENT_ASSERT(i != m_peers.end()); TORRENT_ASSERT(i != m_peers.end());
@ -216,7 +216,7 @@ namespace libtorrent
continue; continue;
} }
int current = i - m_peers.begin(); int current = int(i - m_peers.begin());
TORRENT_ASSERT(current >= 0); TORRENT_ASSERT(current >= 0);
TORRENT_ASSERT(m_peers.size() > 0); TORRENT_ASSERT(m_peers.size() > 0);
TORRENT_ASSERT(i != m_peers.end()); TORRENT_ASSERT(i != m_peers.end());

View File

@ -653,25 +653,25 @@ namespace libtorrent
} }
} }
int const count_downloading = std::count_if( int const count_downloading = int(std::count_if(
m_downloads[piece_pos::piece_downloading].begin() m_downloads[piece_pos::piece_downloading].begin()
, m_downloads[piece_pos::piece_downloading].end() , m_downloads[piece_pos::piece_downloading].end()
, has_index(index)); , has_index(index)));
int const count_full = std::count_if( int const count_full = int(std::count_if(
m_downloads[piece_pos::piece_full].begin() m_downloads[piece_pos::piece_full].begin()
, m_downloads[piece_pos::piece_full].end() , m_downloads[piece_pos::piece_full].end()
, has_index(index)); , has_index(index)));
int const count_finished = std::count_if( int const count_finished = int(std::count_if(
m_downloads[piece_pos::piece_finished].begin() m_downloads[piece_pos::piece_finished].begin()
, m_downloads[piece_pos::piece_finished].end() , m_downloads[piece_pos::piece_finished].end()
, has_index(index)); , has_index(index)));
int const count_zero = std::count_if( int const count_zero = int(std::count_if(
m_downloads[piece_pos::piece_zero_prio].begin() m_downloads[piece_pos::piece_zero_prio].begin()
, m_downloads[piece_pos::piece_zero_prio].end() , m_downloads[piece_pos::piece_zero_prio].end()
, has_index(index)); , has_index(index)));
TORRENT_ASSERT(i->download_queue() == piece_pos::piece_open TORRENT_ASSERT(i->download_queue() == piece_pos::piece_open
|| count_zero + count_downloading + count_full || count_zero + count_downloading + count_full

View File

@ -75,7 +75,8 @@ namespace libtorrent
if (rl.rlim_cur == rlim_infinity) if (rl.rlim_cur == rlim_infinity)
return (std::numeric_limits<int>::max)(); return (std::numeric_limits<int>::max)();
return rl.rlim_cur; return rl.rlim_cur <= std::numeric_limits<int>::max()
? int(rl.rlim_cur) : std::numeric_limits<int>::max();
} }
return 1024; return 1024;
#else #else

View File

@ -104,7 +104,7 @@ namespace libtorrent
if (r != 1) if (r != 1)
{ {
#ifndef BOOST_NO_EXCEPTIONS #ifndef BOOST_NO_EXCEPTIONS
throw system_error(error_code(ERR_get_error(), system_category())); throw system_error(error_code(int(::ERR_get_error()), system_category()));
#else #else
std::terminate(); std::terminate();
#endif #endif

View File

@ -113,22 +113,22 @@ namespace libtorrent
ret.total_uploaded = rd.dict_find_int_value("total_uploaded"); ret.total_uploaded = rd.dict_find_int_value("total_uploaded");
ret.total_downloaded = rd.dict_find_int_value("total_downloaded"); ret.total_downloaded = rd.dict_find_int_value("total_downloaded");
ret.active_time = rd.dict_find_int_value("active_time"); ret.active_time = int(rd.dict_find_int_value("active_time"));
ret.finished_time = rd.dict_find_int_value("finished_time"); ret.finished_time = int(rd.dict_find_int_value("finished_time"));
ret.seeding_time = rd.dict_find_int_value("seeding_time"); ret.seeding_time = int(rd.dict_find_int_value("seeding_time"));
ret.last_seen_complete = rd.dict_find_int_value("last_seen_complete"); ret.last_seen_complete = rd.dict_find_int_value("last_seen_complete");
// scrape data cache // scrape data cache
ret.num_complete = rd.dict_find_int_value("num_complete", -1); ret.num_complete = int(rd.dict_find_int_value("num_complete", -1));
ret.num_incomplete = rd.dict_find_int_value("num_incomplete", -1); ret.num_incomplete = int(rd.dict_find_int_value("num_incomplete", -1));
ret.num_downloaded = rd.dict_find_int_value("num_downloaded", -1); ret.num_downloaded = int(rd.dict_find_int_value("num_downloaded", -1));
// torrent settings // torrent settings
ret.max_uploads = rd.dict_find_int_value("max_uploads", -1); ret.max_uploads = int(rd.dict_find_int_value("max_uploads", -1));
ret.max_connections = rd.dict_find_int_value("max_connections", -1); ret.max_connections = int(rd.dict_find_int_value("max_connections", -1));
ret.upload_limit = rd.dict_find_int_value("upload_rate_limit", -1); ret.upload_limit = int(rd.dict_find_int_value("upload_rate_limit", -1));
ret.download_limit = rd.dict_find_int_value("download_rate_limit", -1); ret.download_limit = int(rd.dict_find_int_value("download_rate_limit", -1));
// torrent state // torrent state
apply_flag(ret.flags, rd, "seed_mode", add_torrent_params::flag_seed_mode); apply_flag(ret.flags, rd, "seed_mode", add_torrent_params::flag_seed_mode);
@ -312,7 +312,7 @@ namespace libtorrent
{ {
bdecode_node e = unfinished_entry.list_at(i); bdecode_node e = unfinished_entry.list_at(i);
if (e.type() != bdecode_node::dict_t) continue; if (e.type() != bdecode_node::dict_t) continue;
int piece = e.dict_find_int_value("piece", -1); int piece = int(e.dict_find_int_value("piece", -1));
if (piece < 0) continue; if (piece < 0) continue;
bdecode_node bitmask = e.dict_find_string("bitmask"); bdecode_node bitmask = e.dict_find_string("bitmask");

View File

@ -203,19 +203,19 @@ namespace aux {
bdecode_node val; bdecode_node val;
val = e.dict_find_int("max_peers_reply"); val = e.dict_find_int("max_peers_reply");
if (val) sett.max_peers_reply = val.int_value(); if (val) sett.max_peers_reply = int(val.int_value());
val = e.dict_find_int("search_branching"); val = e.dict_find_int("search_branching");
if (val) sett.search_branching = val.int_value(); if (val) sett.search_branching = int(val.int_value());
val = e.dict_find_int("max_fail_count"); val = e.dict_find_int("max_fail_count");
if (val) sett.max_fail_count = val.int_value(); if (val) sett.max_fail_count = int(val.int_value());
val = e.dict_find_int("max_torrents"); val = e.dict_find_int("max_torrents");
if (val) sett.max_torrents = val.int_value(); if (val) sett.max_torrents = int(val.int_value());
val = e.dict_find_int("max_dht_items"); val = e.dict_find_int("max_dht_items");
if (val) sett.max_dht_items = val.int_value(); if (val) sett.max_dht_items = int(val.int_value());
val = e.dict_find_int("max_peers"); val = e.dict_find_int("max_peers");
if (val) sett.max_peers = val.int_value(); if (val) sett.max_peers = int(val.int_value());
val = e.dict_find_int("max_torrent_search_reply"); val = e.dict_find_int("max_torrent_search_reply");
if (val) sett.max_torrent_search_reply = val.int_value(); if (val) sett.max_torrent_search_reply = int(val.int_value());
val = e.dict_find_int("restrict_routing_ips"); val = e.dict_find_int("restrict_routing_ips");
if (val) sett.restrict_routing_ips = (val.int_value() != 0); if (val) sett.restrict_routing_ips = (val.int_value() != 0);
val = e.dict_find_int("restrict_search_ips"); val = e.dict_find_int("restrict_search_ips");
@ -231,13 +231,13 @@ namespace aux {
val = e.dict_find_int("ignore_dark_internet"); val = e.dict_find_int("ignore_dark_internet");
if (val) sett.ignore_dark_internet = (val.int_value() != 0); if (val) sett.ignore_dark_internet = (val.int_value() != 0);
val = e.dict_find_int("block_timeout"); val = e.dict_find_int("block_timeout");
if (val) sett.block_timeout = val.int_value(); if (val) sett.block_timeout = int(val.int_value());
val = e.dict_find_int("block_ratelimit"); val = e.dict_find_int("block_ratelimit");
if (val) sett.block_ratelimit = val.int_value(); if (val) sett.block_ratelimit = int(val.int_value());
val = e.dict_find_int("read_only"); val = e.dict_find_int("read_only");
if (val) sett.read_only = (val.int_value() != 0); if (val) sett.read_only = (val.int_value() != 0);
val = e.dict_find_int("item_lifetime"); val = e.dict_find_int("item_lifetime");
if (val) sett.item_lifetime = val.int_value(); if (val) sett.item_lifetime = int(val.int_value());
return sett; return sett;
} }
@ -750,9 +750,9 @@ namespace aux {
{ {
bdecode_node val; bdecode_node val;
val = settings.dict_find_int("port"); val = settings.dict_find_int("port");
if (val) m_settings.set_int(settings_pack::proxy_port, val.int_value()); if (val) m_settings.set_int(settings_pack::proxy_port, int(val.int_value()));
val = settings.dict_find_int("type"); val = settings.dict_find_int("type");
if (val) m_settings.set_int(settings_pack::proxy_type, val.int_value()); if (val) m_settings.set_int(settings_pack::proxy_type, int(val.int_value()));
val = settings.dict_find_int("proxy_hostnames"); val = settings.dict_find_int("proxy_hostnames");
if (val) m_settings.set_bool(settings_pack::proxy_hostnames, val.int_value() != 0); if (val) m_settings.set_bool(settings_pack::proxy_hostnames, val.int_value() != 0);
val = settings.dict_find_int("proxy_peer_connections"); val = settings.dict_find_int("proxy_peer_connections");
@ -774,11 +774,11 @@ namespace aux {
val = settings.dict_find_int("prefer_rc4"); val = settings.dict_find_int("prefer_rc4");
if (val) m_settings.set_bool(settings_pack::prefer_rc4, val.int_value() != 0); if (val) m_settings.set_bool(settings_pack::prefer_rc4, val.int_value() != 0);
val = settings.dict_find_int("out_enc_policy"); val = settings.dict_find_int("out_enc_policy");
if (val) m_settings.set_int(settings_pack::out_enc_policy, val.int_value()); if (val) m_settings.set_int(settings_pack::out_enc_policy, int(val.int_value()));
val = settings.dict_find_int("in_enc_policy"); val = settings.dict_find_int("in_enc_policy");
if (val) m_settings.set_int(settings_pack::in_enc_policy, val.int_value()); if (val) m_settings.set_int(settings_pack::in_enc_policy, int(val.int_value()));
val = settings.dict_find_int("allowed_enc_level"); val = settings.dict_find_int("allowed_enc_level");
if (val) m_settings.set_int(settings_pack::allowed_enc_level, val.int_value()); if (val) m_settings.set_int(settings_pack::allowed_enc_level, int(val.int_value()));
} }
#endif #endif
@ -3843,7 +3843,7 @@ namespace aux {
// unchoked // unchoked
int num_opt_unchoke = m_settings.get_int(settings_pack::num_optimistic_unchoke_slots); int num_opt_unchoke = m_settings.get_int(settings_pack::num_optimistic_unchoke_slots);
int const allowed_unchoke_slots = m_stats_counters[counters::num_unchoke_slots]; int const allowed_unchoke_slots = int(m_stats_counters[counters::num_unchoke_slots]);
if (num_opt_unchoke == 0) num_opt_unchoke = (std::max)(1, allowed_unchoke_slots / 5); if (num_opt_unchoke == 0) num_opt_unchoke = (std::max)(1, allowed_unchoke_slots / 5);
if (num_opt_unchoke > int(opt_unchoke.size())) num_opt_unchoke = if (num_opt_unchoke > int(opt_unchoke.size())) num_opt_unchoke =
int(opt_unchoke.size()); int(opt_unchoke.size());
@ -4146,7 +4146,7 @@ namespace aux {
#endif #endif
int const unchoked_counter_optimistic int const unchoked_counter_optimistic
= m_stats_counters[counters::num_peers_up_unchoked_optimistic]; = int(m_stats_counters[counters::num_peers_up_unchoked_optimistic]);
int const num_opt_unchoke = (unchoked_counter_optimistic == 0) int const num_opt_unchoke = (unchoked_counter_optimistic == 0)
? (std::max)(1, allowed_upload_slots / 5) : unchoked_counter_optimistic; ? (std::max)(1, allowed_upload_slots / 5) : unchoked_counter_optimistic;
@ -5361,37 +5361,37 @@ namespace aux {
s.unchoke_counter = m_unchoke_time_scaler; s.unchoke_counter = m_unchoke_time_scaler;
s.num_dead_peers = int(m_undead_peers.size()); s.num_dead_peers = int(m_undead_peers.size());
s.num_peers = m_stats_counters[counters::num_peers_connected]; s.num_peers = int(m_stats_counters[counters::num_peers_connected]);
s.num_unchoked = m_stats_counters[counters::num_peers_up_unchoked_all]; s.num_unchoked = int(m_stats_counters[counters::num_peers_up_unchoked_all]);
s.allowed_upload_slots = m_stats_counters[counters::num_unchoke_slots]; s.allowed_upload_slots = int(m_stats_counters[counters::num_unchoke_slots]);
s.num_torrents s.num_torrents
= m_stats_counters[counters::num_checking_torrents] = int(m_stats_counters[counters::num_checking_torrents]
+ m_stats_counters[counters::num_stopped_torrents] + m_stats_counters[counters::num_stopped_torrents]
+ m_stats_counters[counters::num_queued_seeding_torrents] + m_stats_counters[counters::num_queued_seeding_torrents]
+ m_stats_counters[counters::num_queued_download_torrents] + m_stats_counters[counters::num_queued_download_torrents]
+ m_stats_counters[counters::num_upload_only_torrents] + m_stats_counters[counters::num_upload_only_torrents]
+ m_stats_counters[counters::num_downloading_torrents] + m_stats_counters[counters::num_downloading_torrents]
+ m_stats_counters[counters::num_seeding_torrents] + m_stats_counters[counters::num_seeding_torrents]
+ m_stats_counters[counters::num_error_torrents]; + m_stats_counters[counters::num_error_torrents]);
s.num_paused_torrents s.num_paused_torrents
= m_stats_counters[counters::num_stopped_torrents] = int(m_stats_counters[counters::num_stopped_torrents]
+ m_stats_counters[counters::num_error_torrents] + m_stats_counters[counters::num_error_torrents]
+ m_stats_counters[counters::num_queued_seeding_torrents] + m_stats_counters[counters::num_queued_seeding_torrents]
+ m_stats_counters[counters::num_queued_download_torrents]; + m_stats_counters[counters::num_queued_download_torrents]);
s.total_redundant_bytes = m_stats_counters[counters::recv_redundant_bytes]; s.total_redundant_bytes = m_stats_counters[counters::recv_redundant_bytes];
s.total_failed_bytes = m_stats_counters[counters::recv_failed_bytes]; s.total_failed_bytes = m_stats_counters[counters::recv_failed_bytes];
s.up_bandwidth_queue = m_stats_counters[counters::limiter_up_queue]; s.up_bandwidth_queue = int(m_stats_counters[counters::limiter_up_queue]);
s.down_bandwidth_queue = m_stats_counters[counters::limiter_down_queue]; s.down_bandwidth_queue = int(m_stats_counters[counters::limiter_down_queue]);
s.up_bandwidth_bytes_queue = m_stats_counters[counters::limiter_up_bytes]; s.up_bandwidth_bytes_queue = int(m_stats_counters[counters::limiter_up_bytes]);
s.down_bandwidth_bytes_queue = m_stats_counters[counters::limiter_down_bytes]; s.down_bandwidth_bytes_queue = int(m_stats_counters[counters::limiter_down_bytes]);
s.disk_write_queue = m_stats_counters[counters::num_peers_down_disk]; s.disk_write_queue = int(m_stats_counters[counters::num_peers_down_disk]);
s.disk_read_queue = m_stats_counters[counters::num_peers_up_disk]; s.disk_read_queue = int(m_stats_counters[counters::num_peers_up_disk]);
s.has_incoming_connections = m_stats_counters[counters::has_incoming_connections] != 0; s.has_incoming_connections = m_stats_counters[counters::has_incoming_connections] != 0;
@ -5455,11 +5455,11 @@ namespace aux {
s.utp_stats.invalid_pkts_in = m_stats_counters[counters::utp_invalid_pkts_in]; s.utp_stats.invalid_pkts_in = m_stats_counters[counters::utp_invalid_pkts_in];
s.utp_stats.redundant_pkts_in = m_stats_counters[counters::utp_redundant_pkts_in]; s.utp_stats.redundant_pkts_in = m_stats_counters[counters::utp_redundant_pkts_in];
s.utp_stats.num_idle = m_stats_counters[counters::num_utp_idle]; s.utp_stats.num_idle = int(m_stats_counters[counters::num_utp_idle]);
s.utp_stats.num_syn_sent = m_stats_counters[counters::num_utp_syn_sent]; s.utp_stats.num_syn_sent = int(m_stats_counters[counters::num_utp_syn_sent]);
s.utp_stats.num_connected = m_stats_counters[counters::num_utp_connected]; s.utp_stats.num_connected = int(m_stats_counters[counters::num_utp_connected]);
s.utp_stats.num_fin_sent = m_stats_counters[counters::num_utp_fin_sent]; s.utp_stats.num_fin_sent = int(m_stats_counters[counters::num_utp_fin_sent]);
s.utp_stats.num_close_wait = m_stats_counters[counters::num_utp_close_wait]; s.utp_stats.num_close_wait = int(m_stats_counters[counters::num_utp_close_wait]);
// this loop is potentially expensive. It could be optimized by // this loop is potentially expensive. It could be optimized by
// simply keeping a global counter // simply keeping a global counter
@ -6840,10 +6840,10 @@ namespace aux {
settings_pack::num_optimistic_unchoke_slots)); settings_pack::num_optimistic_unchoke_slots));
} }
int const unchoked_counter_all = m_stats_counters[counters::num_peers_up_unchoked_all]; int const unchoked_counter_all = int(m_stats_counters[counters::num_peers_up_unchoked_all]);
int const unchoked_counter = m_stats_counters[counters::num_peers_up_unchoked]; int const unchoked_counter = int(m_stats_counters[counters::num_peers_up_unchoked]);
int const unchoked_counter_optimistic int const unchoked_counter_optimistic
= m_stats_counters[counters::num_peers_up_unchoked_optimistic]; = int(m_stats_counters[counters::num_peers_up_unchoked_optimistic]);
TORRENT_ASSERT_VAL(unchoked_counter_all == unchokes_all, unchokes_all); TORRENT_ASSERT_VAL(unchoked_counter_all == unchokes_all, unchokes_all);
TORRENT_ASSERT_VAL(unchoked_counter == unchokes, unchokes); TORRENT_ASSERT_VAL(unchoked_counter == unchokes, unchokes);

View File

@ -114,7 +114,7 @@ namespace libtorrent
int stat_cache::add_error(error_code const& ec) int stat_cache::add_error(error_code const& ec)
{ {
std::vector<error_code>::iterator i = std::find(m_errors.begin(), m_errors.end(), ec); std::vector<error_code>::iterator i = std::find(m_errors.begin(), m_errors.end(), ec);
if (i != m_errors.end()) return i - m_errors.begin(); if (i != m_errors.end()) return int(i - m_errors.begin());
m_errors.push_back(ec); m_errors.push_back(ec);
return int(m_errors.size()) - 1; return int(m_errors.size()) - 1;
} }

View File

@ -271,8 +271,8 @@ namespace libtorrent
#endif #endif
error_code e; error_code e;
int ret = handle->writev(adjusted_offset int ret = int(handle->writev(adjusted_offset
, bufs, e, m_flags); , bufs, e, m_flags));
// set this unconditionally in case the upper layer would like to treat // set this unconditionally in case the upper layer would like to treat
// short reads as errors // short reads as errors
@ -356,8 +356,8 @@ namespace libtorrent
#endif #endif
error_code e; error_code e;
int ret = handle->readv(adjusted_offset int ret = int(handle->readv(adjusted_offset
, bufs, e, m_flags); , bufs, e, m_flags));
// set this unconditionally in case the upper layer would like to treat // set this unconditionally in case the upper layer would like to treat
// short reads as errors // short reads as errors
@ -916,7 +916,7 @@ namespace libtorrent
// this file. We're just sanity-checking whether the files exist // this file. We're just sanity-checking whether the files exist
// or not. // or not.
peer_request const pr = fs.map_file(file_index, 0 peer_request const pr = fs.map_file(file_index, 0
, fs.file_size(file_index) + 1); , int(fs.file_size(file_index) + 1));
i = (std::max)(i + 1, pr.piece); i = (std::max)(i + 1, pr.piece);
} }
return true; return true;