diff --git a/include/libtorrent/aux_/numeric_cast.hpp b/include/libtorrent/aux_/numeric_cast.hpp index b48aea7bf..4ad5056d4 100644 --- a/include/libtorrent/aux_/numeric_cast.hpp +++ b/include/libtorrent/aux_/numeric_cast.hpp @@ -53,6 +53,15 @@ namespace libtorrent { namespace aux { return r; } + // in C++ 17 you can use std::clamp + template ::value>::type> + T clamp(T v, T lo, T hi) + { + TORRENT_ASSERT(lo <= hi); + return (v < lo) ? lo : (hi < v) ? hi : v; + } + }} #endif diff --git a/include/libtorrent/aux_/range.hpp b/include/libtorrent/aux_/range.hpp index 5ca677b69..824abd34a 100644 --- a/include/libtorrent/aux_/range.hpp +++ b/include/libtorrent/aux_/range.hpp @@ -61,4 +61,3 @@ namespace libtorrent { namespace aux { }} #endif - diff --git a/include/libtorrent/aux_/throw.hpp b/include/libtorrent/aux_/throw.hpp index fe44e5276..6123bf0f7 100644 --- a/include/libtorrent/aux_/throw.hpp +++ b/include/libtorrent/aux_/throw.hpp @@ -51,4 +51,3 @@ namespace libtorrent { namespace aux }} #endif - diff --git a/include/libtorrent/bandwidth_limit.hpp b/include/libtorrent/bandwidth_limit.hpp index 2b408ef70..0057f4170 100644 --- a/include/libtorrent/bandwidth_limit.hpp +++ b/include/libtorrent/bandwidth_limit.hpp @@ -98,4 +98,3 @@ private: } #endif - diff --git a/include/libtorrent/ip_filter.hpp b/include/libtorrent/ip_filter.hpp index 90af56a61..e795e9d90 100644 --- a/include/libtorrent/ip_filter.hpp +++ b/include/libtorrent/ip_filter.hpp @@ -286,7 +286,7 @@ struct TORRENT_EXPORT ip_filter // can currently be 0 or ``ip_filter::blocked``. The complexity of this operation // is O(``log`` n), where n is the minimum number of non-overlapping ranges to describe // the current filter. - int access(address const& addr) const; + std::uint32_t access(address const& addr) const; #if TORRENT_USE_IPV6 using filter_tuple_t = std::tuple> @@ -338,7 +338,7 @@ public: // test the specified port (``port``) for whether it is blocked // or not. The returned value is the flags set for this port. // see access_flags. - int access(std::uint16_t port) const; + std::uint32_t access(std::uint16_t port) const; private: diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 2781aae7c..fdcf27661 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -95,6 +95,8 @@ namespace libtorrent class bt_peer_connection; struct listen_socket_t; + constexpr int default_piece_priority = 4; + enum class waste_reason { piece_timed_out, piece_cancelled, piece_unknown, piece_seed diff --git a/include/libtorrent/union_endpoint.hpp b/include/libtorrent/union_endpoint.hpp index 0f236e181..912139cab 100644 --- a/include/libtorrent/union_endpoint.hpp +++ b/include/libtorrent/union_endpoint.hpp @@ -127,4 +127,3 @@ namespace libtorrent } #endif - diff --git a/include/libtorrent/utf8.hpp b/include/libtorrent/utf8.hpp index 07b9eaca7..ff1208a84 100644 --- a/include/libtorrent/utf8.hpp +++ b/include/libtorrent/utf8.hpp @@ -83,4 +83,3 @@ namespace libtorrent #endif // !BOOST_NO_STD_WSTRING #endif - diff --git a/src/file_storage.cpp b/src/file_storage.cpp index d98e8f0ff..30d15d005 100644 --- a/src/file_storage.cpp +++ b/src/file_storage.cpp @@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/string_util.hpp" // for allocate_string_copy #include "libtorrent/file.hpp" #include "libtorrent/utf8.hpp" +#include "libtorrent/aux_/numeric_cast.hpp" #include "libtorrent/aux_/disable_warnings_push.hpp" #include @@ -157,7 +158,7 @@ namespace libtorrent , [&] (std::string const& str) { if (int(str.size()) != branch_len) return false; - return std::memcmp(str.c_str(), branch_path, branch_len) == 0; + return std::memcmp(str.c_str(), branch_path, aux::numeric_cast(branch_len)) == 0; }); if (p == m_paths.rend()) @@ -168,7 +169,7 @@ namespace libtorrent // poor man's emplace back m_paths.resize(m_paths.size() + 1); - m_paths.back().assign(branch_path, branch_len); + m_paths.back().assign(branch_path, aux::numeric_cast(branch_len)); } else { @@ -303,7 +304,7 @@ namespace libtorrent else if (borrow_string) { name = n; - name_len = string_len; + name_len = aux::numeric_cast(string_len); } else { @@ -384,7 +385,7 @@ namespace libtorrent { // find the file iterator and file offset internal_file_entry target; - target.offset = offset; + target.offset = aux::numeric_cast(offset); TORRENT_ASSERT(!compare_file_offset(target, m_files.front())); auto file_iter = std::upper_bound( @@ -405,7 +406,7 @@ namespace libtorrent { // find the file iterator and file offset internal_file_entry target; - target.offset = offset; + target.offset = aux::numeric_cast(offset); TORRENT_ASSERT(!compare_file_offset(target, m_files.front())); auto file_iter = std::upper_bound( @@ -438,13 +439,13 @@ namespace libtorrent // find the file iterator and file offset internal_file_entry target; - target.offset = static_cast(piece) * std::int64_t(m_piece_length) + offset; - TORRENT_ASSERT_PRECOND(std::int64_t(target.offset + size) <= m_total_size); + target.offset = aux::numeric_cast(static_cast(piece) * std::int64_t(m_piece_length) + offset); + TORRENT_ASSERT_PRECOND(std::int64_t(target.offset) + size <= m_total_size); TORRENT_ASSERT(!compare_file_offset(target, m_files.front())); // in case the size is past the end, fix it up - if (std::int64_t(target.offset + size) > m_total_size) - size = int(m_total_size - target.offset); + if (std::int64_t(target.offset) + size > m_total_size) + size = aux::numeric_cast(m_total_size - std::int64_t(target.offset)); auto file_iter = std::upper_bound( m_files.begin(), m_files.end(), target, compare_file_offset); @@ -465,7 +466,7 @@ namespace libtorrent + file_base_deprecated(f.file_index) #endif ; - f.size = std::min(std::uint64_t(file_iter->size) - file_offset, std::uint64_t(size)); + f.size = std::min(std::int64_t(file_iter->size) - file_offset, std::int64_t(size)); TORRENT_ASSERT(f.size <= size); size -= int(f.size); file_offset += f.size; @@ -581,8 +582,8 @@ namespace libtorrent if (filename) e.set_name(filename, true, filename_len); - e.size = file_size; - e.offset = m_total_size; + e.size = aux::numeric_cast(file_size); + e.offset = aux::numeric_cast(m_total_size); e.pad_file = (file_flags & file_storage::flag_pad_file) != 0; e.hidden_attribute = (file_flags & file_storage::flag_hidden) != 0; e.executable_attribute = (file_flags & file_storage::flag_executable) != 0; @@ -638,7 +639,7 @@ namespace libtorrent void process_string_lowercase(CRC& crc, string_view str) { for (char const c : str) - crc.process_byte(to_lower(c)); + crc.process_byte(to_lower(c) & 0xff); } template @@ -652,7 +653,7 @@ namespace libtorrent { if (*str == TORRENT_SEPARATOR) table.insert(crc.checksum()); - crc.process_byte(to_lower(*str)); + crc.process_byte(to_lower(*str) & 0xff); } table.insert(crc.checksum()); } @@ -975,7 +976,7 @@ namespace libtorrent { // a file whose size fits the alignment always takes priority, // since it will let us keep placing aligned files - if ((k->size % alignment) == 0) + if ((k->size % aux::numeric_cast(alignment)) == 0) { best_match = k; break; @@ -1029,7 +1030,7 @@ namespace libtorrent int cur_index = int(i - m_files.begin()); reorder_file(index, cur_index); i = m_files.begin() + cur_index; - i->offset = off; + i->offset = aux::numeric_cast(off); off += i->size; continue; } @@ -1049,7 +1050,7 @@ namespace libtorrent TORRENT_ASSERT((off % alignment) == 0); continue; } - i->offset = off; + i->offset = aux::numeric_cast(off); off += i->size; if (tail_padding @@ -1084,8 +1085,8 @@ namespace libtorrent internal_file_entry& e = m_files.back(); // i may have been invalidated, refresh it i = m_files.begin() + cur_index; - e.size = size; - e.offset = offset; + e.size = aux::numeric_cast(size); + e.offset = aux::numeric_cast(offset); char name[30]; std::snprintf(name, sizeof(name), ".pad" TORRENT_SEPARATOR_STR "%d" , pad_file_counter); diff --git a/src/ip_filter.cpp b/src/ip_filter.cpp index cc76fb807..52ef97530 100644 --- a/src/ip_filter.cpp +++ b/src/ip_filter.cpp @@ -52,7 +52,7 @@ namespace libtorrent TORRENT_ASSERT_FAIL(); } - int ip_filter::access(address const& addr) const + std::uint32_t ip_filter::access(address const& addr) const { if (addr.is_v4()) return m_filter4.access(addr.to_v4().to_bytes()); @@ -79,7 +79,7 @@ namespace libtorrent m_filter.add_rule(first, last, flags); } - int port_filter::access(std::uint16_t port) const + std::uint32_t port_filter::access(std::uint16_t port) const { return m_filter.access(port); } @@ -93,4 +93,3 @@ namespace libtorrent } */ } - diff --git a/src/kademlia/dht_storage.cpp b/src/kademlia/dht_storage.cpp index f7571bcbf..691a6fd20 100644 --- a/src/kademlia/dht_storage.cpp +++ b/src/kademlia/dht_storage.cpp @@ -46,6 +46,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include namespace libtorrent { namespace dht { @@ -183,12 +184,6 @@ namespace int count() const { return int(samples.size()); } }; - int clamp(int v, int lo, int hi) - { - TORRENT_ASSERT(lo <= hi); - return (v < lo) ? lo : (hi < v) ? hi : v; - } - class dht_default_storage final : public dht_storage_interface, boost::noncopyable { public: @@ -473,7 +468,7 @@ namespace int get_infohashes_sample(entry& item) override { - item["interval"] = clamp(m_settings.sample_infohashes_interval + item["interval"] = aux::clamp(m_settings.sample_infohashes_interval , 0, sample_infohashes_interval_max); item["num"] = int(m_map.size()); @@ -571,10 +566,10 @@ namespace void refresh_infohashes_sample() { time_point const now = aux::time_now(); - int const interval = clamp(m_settings.sample_infohashes_interval + int const interval = aux::clamp(m_settings.sample_infohashes_interval , 0, sample_infohashes_interval_max); - int const max_count = clamp(m_settings.max_infohashes_sample_count + int const max_count = aux::clamp(m_settings.max_infohashes_sample_count , 0, infohashes_sample_count_max); int const count = std::min(max_count, int(m_map.size())); diff --git a/src/kademlia/item.cpp b/src/kademlia/item.cpp index ed70b6843..3066bbf05 100644 --- a/src/kademlia/item.cpp +++ b/src/kademlia/item.cpp @@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include // for snprintf #include // for PRId64 et.al. @@ -61,17 +62,17 @@ namespace #endif char* ptr = out.data(); - size_t left = out.size() - (ptr - out.data()); + std::size_t left = out.size() - aux::numeric_cast(ptr - out.data()); if (salt.size() > 0) { ptr += std::snprintf(ptr, left, "4:salt%d:", int(salt.size())); - left = out.size() - (ptr - out.data()); + left = out.size() - aux::numeric_cast(ptr - out.data()); std::memcpy(ptr, salt.data(), std::min(salt.size(), left)); ptr += std::min(salt.size(), left); - left = out.size() - (ptr - out.data()); + left = out.size() - aux::numeric_cast(ptr - out.data()); } ptr += std::snprintf(ptr, left, "3:seqi%" PRId64 "e1:v", seq.value); - left = out.size() - (ptr - out.data()); + left = out.size() - aux::numeric_cast(ptr - out.data()); std::memcpy(ptr, v.data(), std::min(v.size(), left)); ptr += std::min(v.size(), left); TORRENT_ASSERT((ptr - out.data()) <= int(out.size())); @@ -165,7 +166,7 @@ void item::assign(entry v, span salt char buffer[1000]; int bsize = bencode(buffer, v); TORRENT_ASSERT(bsize <= 1000); - m_sig = sign_mutable_item(span(buffer, bsize) + m_sig = sign_mutable_item({buffer, aux::numeric_cast(bsize)} , salt, seq, pk, sk); m_salt.assign(salt.data(), salt.size()); m_pk = pk; diff --git a/src/natpmp.cpp b/src/natpmp.cpp index c8fcd4c35..ab6e78934 100644 --- a/src/natpmp.cpp +++ b/src/natpmp.cpp @@ -55,6 +55,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/aux_/time.hpp" #include "libtorrent/debug.hpp" #include "libtorrent/aux_/escape_string.hpp" +#include "libtorrent/aux_/numeric_cast.hpp" namespace libtorrent { @@ -207,7 +208,7 @@ void natpmp::disable(error_code const& ec) close_impl(); } -void natpmp::delete_mapping(int index) +void natpmp::delete_mapping(int const index) { TORRENT_ASSERT(is_single_thread()); @@ -471,7 +472,7 @@ void natpmp::on_reply(error_code const& e int version = read_uint8(in); int cmd = read_uint8(in); int result = read_uint16(in); - int time = read_uint32(in); + int time = aux::numeric_cast(read_uint32(in)); TORRENT_UNUSED(version); TORRENT_UNUSED(time); @@ -500,7 +501,7 @@ void natpmp::on_reply(error_code const& e int const private_port = read_uint16(in); int const public_port = read_uint16(in); - int const lifetime = read_uint32(in); + int const lifetime = aux::numeric_cast(read_uint32(in)); portmap_protocol const protocol = (cmd - 128 == 1) ? portmap_protocol::udp @@ -515,7 +516,7 @@ void natpmp::on_reply(error_code const& e if (version != 0) { - std::snprintf(msg + num_chars, sizeof(msg) - num_chars, "unexpected version: %u" + std::snprintf(msg + num_chars, sizeof(msg) - aux::numeric_cast(num_chars), "unexpected version: %u" , version); log("%s", msg); } @@ -523,8 +524,7 @@ void natpmp::on_reply(error_code const& e mapping_t* m = nullptr; int index = -1; - for (std::vector::iterator i = m_mappings.begin() - , end(m_mappings.end()); i != end; ++i) + for (auto i = m_mappings.begin(), end(m_mappings.end()); i != end; ++i) { if (private_port != i->local_port) continue; if (protocol != i->protocol) continue; @@ -538,7 +538,7 @@ void natpmp::on_reply(error_code const& e if (m == nullptr) { #ifndef TORRENT_DISABLE_LOGGING - snprintf(msg + num_chars, sizeof(msg) - num_chars, " not found in map table"); + snprintf(msg + num_chars, sizeof(msg) - aux::numeric_cast(num_chars), " not found in map table"); log("%s", msg); #endif return; @@ -645,7 +645,7 @@ void natpmp::update_expiration_timer() } } -void natpmp::mapping_expired(error_code const& e, int i) +void natpmp::mapping_expired(error_code const& e, int const i) { TORRENT_ASSERT(is_single_thread()); COMPLETE_ASYNC("natpmp::mapping_expired"); diff --git a/src/peer_list.cpp b/src/peer_list.cpp index 6806ef12b..cf729cd52 100644 --- a/src/peer_list.cpp +++ b/src/peer_list.cpp @@ -340,12 +340,12 @@ namespace libtorrent if (bool(m_finished) != state->is_finished) recalculate_connect_candidates(state); - int round_robin = random(std::uint32_t(m_peers.size()-1)); + int round_robin = aux::numeric_cast(random(std::uint32_t(m_peers.size() - 1))); int low_watermark = max_peerlist_size * 95 / 100; if (low_watermark == max_peerlist_size) --low_watermark; - for (int iterations = (std::min)(int(m_peers.size()), 300); + for (int iterations = std::min(int(m_peers.size()), 300); iterations > 0; --iterations) { if (int(m_peers.size()) < low_watermark) @@ -430,20 +430,20 @@ namespace libtorrent // failcount is a 5 bit value if (p->failcount == 31) return; - const bool was_conn_cand = is_connect_candidate(*p); + bool const was_conn_cand = is_connect_candidate(*p); ++p->failcount; if (was_conn_cand && !is_connect_candidate(*p)) update_connect_candidates(-1); } - void peer_list::set_failcount(torrent_peer* p, int f) + void peer_list::set_failcount(torrent_peer* p, int const f) { TORRENT_ASSERT(is_single_thread()); INVARIANT_CHECK; TORRENT_ASSERT(p->in_use); - const bool was_conn_cand = is_connect_candidate(*p); - p->failcount = f; + bool const was_conn_cand = is_connect_candidate(*p); + p->failcount = aux::numeric_cast(f); if (was_conn_cand != is_connect_candidate(*p)) { update_connect_candidates(was_conn_cand ? -1 : 1); @@ -489,7 +489,7 @@ namespace libtorrent // TODO: 2 it would be nice if there was a way to iterate over these // torrent_peer objects in the order they are allocated in the pool // instead. It would probably be more efficient - for (int iterations = (std::min)(int(m_peers.size()), 300); + for (int iterations = std::min(int(m_peers.size()), 300); iterations > 0; --iterations) { ++state->loop_counter; @@ -543,7 +543,7 @@ namespace libtorrent peers.resize(candidate_count - 1); // insert this candidate sorted into peers - std::vector::iterator i = std::lower_bound(peers.begin(), peers.end() + auto const i = std::lower_bound(peers.begin(), peers.end() , &pe, std::bind(&peer_list::compare_peer, this, _1, _2, std::cref(external), external_port)); peers.insert(i, &pe); diff --git a/src/read_resume_data.cpp b/src/read_resume_data.cpp index 096c050de..99488a58b 100644 --- a/src/read_resume_data.cpp +++ b/src/read_resume_data.cpp @@ -38,6 +38,8 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/socket_io.hpp" // for read_*_endpoint() #include "libtorrent/hasher.hpp" #include "libtorrent/torrent_info.hpp" +#include "libtorrent/aux_/numeric_cast.hpp" +#include "libtorrent/torrent.hpp" // for default_piece_priority namespace libtorrent { @@ -165,13 +167,15 @@ namespace libtorrent if (file_priority) { int const num_files = file_priority.list_size(); - ret.file_priorities.resize(num_files, 4); + ret.file_priorities.resize(aux::numeric_cast(num_files) + , default_piece_priority); for (int i = 0; i < num_files; ++i) { - ret.file_priorities[i] = std::uint8_t( - file_priority.list_int_value_at(i, 1)); + std::size_t const idx = std::size_t(i); + ret.file_priorities[idx] = aux::clamp( + file_priority.list_int_value_at(i, default_piece_priority), std::int64_t(0), std::int64_t(7)) & 0xff; // this is suspicious, leave seed mode - if (ret.file_priorities[i] == 0) + if (ret.file_priorities[idx] == 0) { ret.flags &= ~add_torrent_params::flag_seed_mode; } @@ -239,9 +243,9 @@ namespace libtorrent bdecode_node mt = rd.dict_find_string("merkle tree"); if (mt) { - ret.merkle_tree.resize(mt.string_length() / 20); - std::memcpy(&ret.merkle_tree[0], mt.string_ptr() - , int(ret.merkle_tree.size()) * 20); + ret.merkle_tree.resize(aux::numeric_cast(mt.string_length() / 20)); + std::memcpy(ret.merkle_tree.data(), mt.string_ptr() + , ret.merkle_tree.size() * 20); } // some sanity checking. Maybe we shouldn't be in seed mode anymore @@ -266,10 +270,10 @@ namespace libtorrent if (bdecode_node piece_priority = rd.dict_find_string("piece_priority")) { char const* prio_str = piece_priority.string_ptr(); - ret.piece_priorities.resize(piece_priority.string_length()); - for (int i = 0; i < int(ret.piece_priorities.size()); ++i) + ret.piece_priorities.resize(aux::numeric_cast(piece_priority.string_length())); + for (std::size_t i = 0; i < ret.piece_priorities.size(); ++i) { - ret.piece_priorities[i] = prio_str[i]; + ret.piece_priorities[i] = aux::clamp(int(prio_str[i]), 0, 7) & 0xff; } } diff --git a/src/resolve_links.cpp b/src/resolve_links.cpp index bbf240173..e3d59b0fd 100644 --- a/src/resolve_links.cpp +++ b/src/resolve_links.cpp @@ -32,6 +32,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/resolve_links.hpp" #include "libtorrent/torrent_info.hpp" +#include "libtorrent/aux_/numeric_cast.hpp" namespace libtorrent { @@ -45,7 +46,7 @@ resolve_links::resolve_links(std::shared_ptr ti) int piece_size = ti->piece_length(); file_storage const& fs = ti->files(); - m_file_sizes.reserve(fs.num_files()); + m_file_sizes.reserve(aux::numeric_cast(fs.num_files())); for (file_index_t i(0); i < fs.end_file(); ++i) { // don't match pad-files, and don't match files that aren't aligned to @@ -71,7 +72,7 @@ void resolve_links::match(std::shared_ptr const& ti int piece_size = ti->piece_length(); file_storage const& fs = ti->files(); - m_file_sizes.reserve(fs.num_files()); + m_file_sizes.reserve(aux::numeric_cast(fs.num_files())); for (file_index_t i(0); i < fs.end_file(); ++i) { // for every file in the other torrent, see if we have one that match diff --git a/src/stat_cache.cpp b/src/stat_cache.cpp index abd491c64..93ba94f47 100644 --- a/src/stat_cache.cpp +++ b/src/stat_cache.cpp @@ -56,7 +56,7 @@ namespace libtorrent if (i >= m_stat_cache.end_index()) m_stat_cache.resize(static_cast(i) + 1, not_in_cache); - int error_index = add_error(ec); + int const error_index = add_error(ec); m_stat_cache[i].file_size = file_error - error_index; } diff --git a/src/torrent.cpp b/src/torrent.cpp index 434178d0f..e2b96cd6e 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -54,6 +54,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/aux_/disable_warnings_pop.hpp" +#include "libtorrent/torrent.hpp" #include "libtorrent/torrent_handle.hpp" #include "libtorrent/announce_entry.hpp" #include "libtorrent/torrent_info.hpp" @@ -124,7 +125,6 @@ namespace libtorrent } return ret; } - constexpr int default_piece_priority = 4; } // anonymous namespace diff --git a/src/utf8.cpp b/src/utf8.cpp index 7cb77175c..edb5290cf 100644 --- a/src/utf8.cpp +++ b/src/utf8.cpp @@ -42,6 +42,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/error_code.hpp" #include "libtorrent/ConvertUTF.h" #include "libtorrent/aux_/throw.hpp" +#include "libtorrent/aux_/numeric_cast.hpp" #ifdef __clang__ @@ -92,7 +93,7 @@ namespace libtorrent , std::back_inserter(wide)); return static_cast(ret); } - wide.resize(dst_start - wide.c_str()); + wide.resize(aux::numeric_cast(dst_start - wide.c_str())); return static_cast(ret); } }; @@ -121,7 +122,7 @@ namespace libtorrent , std::back_inserter(wide)); return static_cast(ret); } - wide.resize(dst_start - wide.c_str()); + wide.resize(aux::numeric_cast(dst_start - wide.c_str())); return static_cast(ret); } }; @@ -156,7 +157,7 @@ namespace libtorrent , reinterpret_cast(&dst_start) , reinterpret_cast(dst_start + utf8.size()) , lenientConversion); - utf8.resize(dst_start - &utf8[0]); + utf8.resize(aux::numeric_cast(dst_start - &utf8[0])); return static_cast(ret); } }; @@ -176,7 +177,7 @@ namespace libtorrent , reinterpret_cast(&dst_start) , reinterpret_cast(dst_start + utf8.size()) , lenientConversion); - utf8.resize(dst_start - &utf8[0]); + utf8.resize(aux::numeric_cast(dst_start - &utf8[0])); return static_cast(ret); } }; @@ -274,4 +275,3 @@ namespace libtorrent #endif #endif - diff --git a/test/test_ip_filter.cpp b/test/test_ip_filter.cpp index e5e1b8831..681a30ce9 100644 --- a/test/test_ip_filter.cpp +++ b/test/test_ip_filter.cpp @@ -82,8 +82,8 @@ void test_rules_invariant(std::vector> const& r, ip_filter const& f) for (iterator i(r.begin()), j(std::next(r.begin())) , end(r.end()); j != end; ++j, ++i) { - TEST_EQUAL(f.access(i->last), int(i->flags)); - TEST_EQUAL(f.access(j->first), int(j->flags)); + TEST_EQUAL(f.access(i->last), i->flags); + TEST_EQUAL(f.access(j->first), j->flags); TEST_CHECK(detail::plus_one(i->last.to_bytes()) == j->first.to_bytes()); } }