From 2d3e39422614f6fed5ff3fb0c8c747d5db68387e Mon Sep 17 00:00:00 2001 From: Alden Torres Date: Fri, 2 Feb 2018 07:28:01 -0500 Subject: [PATCH] fixing warnings in tests code, part10, final --- test/Jamfile | 20 +++++++++---------- test/test_dht.cpp | 40 +++++++++++++++++++------------------ test/test_file.cpp | 2 -- test/test_ip_filter.cpp | 1 - test/test_natpmp.cpp | 13 +++++++----- test/test_packet_buffer.cpp | 3 +-- test/test_priority.cpp | 1 + test/test_resume.cpp | 6 +++--- test/test_storage.cpp | 3 ++- 9 files changed, 45 insertions(+), 44 deletions(-) diff --git a/test/Jamfile b/test/Jamfile index 842dea6e9..9769f8c1f 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -7,8 +7,7 @@ exe test_natpmp : test_natpmp.cpp : # requirements /torrent//torrent on -# disable warning C4373: virtual function overrides, previous versions of the compiler did not override when parameters only differed by const/volatile qualifiers - msvc:/wd4373 + @warnings : # default-build multi on @@ -22,8 +21,7 @@ exe enum_if : enum_if.cpp : # requirements /torrent//torrent on -# disable warning C4373: virtual function overrides, previous versions of the compiler did not override when parameters only differed by const/volatile qualifiers - msvc:/wd4373 + @warnings : # default-build multi on @@ -80,13 +78,13 @@ project on libtorrent_test /torrent//torrent - darwin:-Wno-unused-command-line-argument -# disable warning C4275: non DLL-interface classkey 'identifier' used as base for DLL-interface classkey 'identifier' - msvc:/wd4275 -# disable warning C4373: virtual function overrides, previous versions of the compiler did not override when parameters only differed by const/volatile qualifiers - msvc:/wd4373 - msvc:/wd4503 - msvc:_SCL_SECURE_NO_WARNINGS + # C4127: conditional expression is constant + msvc:/wd4127 + # C4309: 'conversion' : truncation of constant value + msvc:/wd4309 + # C4310: cast truncates constant value + msvc:/wd4310 + @warnings on : default-build multi diff --git a/test/test_dht.cpp b/test/test_dht.cpp index d8a6ef324..0084b7331 100644 --- a/test/test_dht.cpp +++ b/test/test_dht.cpp @@ -642,10 +642,11 @@ dht::key_desc_t const sample_infohashes_desc[] = { void print_state(std::ostream& os, routing_table const& table) { +#define BUFFER_CURSOR_POS &buf[std::size_t(cursor)], buf.size() - std::size_t(cursor) std::vector buf(2048); int cursor = 0; - cursor += std::snprintf(&buf[cursor], buf.size() - cursor + cursor += std::snprintf(BUFFER_CURSOR_POS , "kademlia routing table state\n" "bucket_size: %d\n" "global node count: %" PRId64 "\n" @@ -661,27 +662,27 @@ void print_state(std::ostream& os, routing_table const& table) for (auto i = table.buckets().begin(), end(table.buckets().end()); i != end; ++i, ++idx) { - cursor += std::snprintf(&buf[cursor], buf.size() - cursor + cursor += std::snprintf(BUFFER_CURSOR_POS , "%2d: ", idx); for (int k = 0; k < int(i->live_nodes.size()); ++k) - cursor += std::snprintf(&buf[cursor], buf.size() - cursor, "#"); + cursor += std::snprintf(BUFFER_CURSOR_POS, "#"); for (int k = 0; k < int(i->replacements.size()); ++k) - cursor += std::snprintf(&buf[cursor], buf.size() - cursor, "-"); - cursor += std::snprintf(&buf[cursor], buf.size() - cursor, "\n"); + cursor += std::snprintf(BUFFER_CURSOR_POS, "-"); + cursor += std::snprintf(BUFFER_CURSOR_POS, "\n"); if (cursor > int(buf.size()) - 500) buf.resize(buf.size() * 3 / 2); } time_point now = aux::time_now(); - cursor += std::snprintf(&buf[cursor], buf.size() - cursor + cursor += std::snprintf(BUFFER_CURSOR_POS , "\nnodes:"); int bucket_index = 0; for (auto i = table.buckets().begin(), end(table.buckets().end()); i != end; ++i, ++bucket_index) { - cursor += std::snprintf(&buf[cursor], buf.size() - cursor + cursor += std::snprintf(BUFFER_CURSOR_POS , "\n=== BUCKET == %d == %d|%d ==== \n" , bucket_index, int(i->live_nodes.size()) , int(i->replacements.size())); @@ -712,23 +713,23 @@ void print_state(std::ostream& os, routing_table const& table) node_id id = j->id; id <<= id_shift; - cursor += std::snprintf(&buf[cursor], buf.size() - cursor + cursor += std::snprintf(BUFFER_CURSOR_POS , " prefix: %2x id: %s" , ((id[0] & top_mask) >> mask_shift) , aux::to_hex(j->id).c_str()); if (j->rtt == 0xffff) { - cursor += std::snprintf(&buf[cursor], buf.size() - cursor + cursor += std::snprintf(BUFFER_CURSOR_POS , " rtt: "); } else { - cursor += std::snprintf(&buf[cursor], buf.size() - cursor + cursor += std::snprintf(BUFFER_CURSOR_POS , " rtt: %4d", j->rtt); } - cursor += std::snprintf(&buf[cursor], buf.size() - cursor + cursor += std::snprintf(BUFFER_CURSOR_POS , " fail: %4d ping: %d dist: %3d" , j->fail_count() , j->pinged() @@ -736,22 +737,22 @@ void print_state(std::ostream& os, routing_table const& table) if (j->last_queried == min_time()) { - cursor += std::snprintf(&buf[cursor], buf.size() - cursor + cursor += std::snprintf(BUFFER_CURSOR_POS , " query: "); } else { - cursor += std::snprintf(&buf[cursor], buf.size() - cursor + cursor += std::snprintf(BUFFER_CURSOR_POS , " query: %3d", int(total_seconds(now - j->last_queried))); } - cursor += std::snprintf(&buf[cursor], buf.size() - cursor + cursor += std::snprintf(BUFFER_CURSOR_POS , " ip: %s\n", print_endpoint(j->ep()).c_str()); if (cursor > int(buf.size()) - 500) buf.resize(buf.size() * 3 / 2); } } - cursor += std::snprintf(&buf[cursor], buf.size() - cursor + cursor += std::snprintf(BUFFER_CURSOR_POS , "\nnode spread per bucket:\n"); bucket_index = 0; for (auto i = table.buckets().begin(), end(table.buckets().end()); @@ -796,20 +797,21 @@ void print_state(std::ostream& os, routing_table const& table) sub_buckets[b] = true; } - cursor += std::snprintf(&buf[cursor], buf.size() - cursor + cursor += std::snprintf(BUFFER_CURSOR_POS , "%2d mask: %2x: [", bucket_index, (top_mask >> mask_shift)); for (int j = 0; j < bucket_size_limit; ++j) { - cursor += std::snprintf(&buf[cursor], buf.size() - cursor + cursor += std::snprintf(BUFFER_CURSOR_POS , (sub_buckets[j] ? "X" : " ")); } - cursor += std::snprintf(&buf[cursor], buf.size() - cursor + cursor += std::snprintf(BUFFER_CURSOR_POS , "]\n"); if (cursor > int(buf.size()) - 500) buf.resize(buf.size() * 3 / 2); } - buf[cursor] = '\0'; + buf[std::size_t(cursor)] = '\0'; os << &buf[0]; +#undef BUFFER_CURSOR_POS } } // anonymous namespace diff --git a/test/test_file.cpp b/test/test_file.cpp index 6e3afc763..00dfb8e91 100644 --- a/test/test_file.cpp +++ b/test/test_file.cpp @@ -475,8 +475,6 @@ TORRENT_TEST(unc_tests) std::string long_file_name2 { long_file_name1 }; long_file_name2.back() = '2'; - error_code ec; - lt::create_directory(long_component_name, ec); TEST_EQUAL(ec, error_code()); TEST_CHECK(lt::exists(long_component_name)); diff --git a/test/test_ip_filter.cpp b/test/test_ip_filter.cpp index ed04b14a1..815c6c94d 100644 --- a/test/test_ip_filter.cpp +++ b/test/test_ip_filter.cpp @@ -66,7 +66,6 @@ void test_rules_invariant(std::vector> const& r, ip_filter const& f) TEST_CHECK(!r.empty()); if (r.empty()) return; - error_code ec; if (sizeof(r.front().first) == sizeof(address_v4)) { TEST_CHECK(r.front().first == addr("0.0.0.0")); diff --git a/test/test_natpmp.cpp b/test/test_natpmp.cpp index 41e3564dd..6d509d341 100644 --- a/test/test_natpmp.cpp +++ b/test/test_natpmp.cpp @@ -33,6 +33,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/natpmp.hpp" #include "libtorrent/socket.hpp" #include "libtorrent/socket_io.hpp" +#include "libtorrent/aux_/numeric_cast.hpp" #include #include #include @@ -43,10 +44,12 @@ namespace { struct natpmp_callback : aux::portmap_callback { + virtual ~natpmp_callback() = default; + void on_port_mapping(port_mapping_t const mapping , address const& ip, int port , portmap_protocol const protocol, error_code const& err - , portmap_transport const transport) override + , portmap_transport) override { std::cout << "mapping: " << mapping @@ -56,12 +59,12 @@ namespace << ", error: \"" << err.message() << "\"\n"; } #ifndef TORRENT_DISABLE_LOGGING - virtual bool should_log_portmap(portmap_transport transport) const override + virtual bool should_log_portmap(portmap_transport) const override { return true; } - virtual void log_portmap(portmap_transport transport, char const* msg) const override + virtual void log_portmap(portmap_transport, char const* msg) const override { std::cout << msg << std::endl; } @@ -86,9 +89,9 @@ int main(int argc, char* argv[]) deadline_timer timer(ios); auto const tcp_map = natpmp_handler->add_mapping(portmap_protocol::tcp - , atoi(argv[1]), tcp::endpoint({}, atoi(argv[1]))); + , atoi(argv[1]), tcp::endpoint({}, aux::numeric_cast(atoi(argv[1])))); natpmp_handler->add_mapping(portmap_protocol::udp, atoi(argv[2]) - , tcp::endpoint({}, atoi(argv[2]))); + , tcp::endpoint({}, aux::numeric_cast(atoi(argv[2])))); error_code ec; timer.expires_from_now(seconds(2), ec); diff --git a/test/test_packet_buffer.cpp b/test/test_packet_buffer.cpp index 56b1a000f..6fa7cb43f 100644 --- a/test/test_packet_buffer.cpp +++ b/test/test_packet_buffer.cpp @@ -33,7 +33,6 @@ POSSIBILITY OF SUCH DAMAGE. #include "test.hpp" #include "libtorrent/packet_buffer.hpp" #include "libtorrent/packet_pool.hpp" -#include "libtorrent/aux_/numeric_cast.hpp" using lt::packet_buffer; using lt::packet_ptr; @@ -45,7 +44,7 @@ namespace { packet_ptr make_pkt(packet_pool& pool, int const val) { packet_ptr ret = pool.acquire(20); - *reinterpret_cast(ret->buf) = val; + *reinterpret_cast(ret->buf) = std::uint8_t(val); return ret; } diff --git a/test/test_priority.cpp b/test/test_priority.cpp index e082be33e..9d1b9261b 100644 --- a/test/test_priority.cpp +++ b/test/test_priority.cpp @@ -289,6 +289,7 @@ done: std::cout << "re-adding" << std::endl; add_torrent_params p; + TORRENT_UNUSED(test_deprecated); #ifndef TORRENT_NO_DEPRECATE if (test_deprecated) { diff --git a/test/test_resume.cpp b/test/test_resume.cpp index 8479efd71..6769027f1 100644 --- a/test/test_resume.cpp +++ b/test/test_resume.cpp @@ -155,7 +155,7 @@ torrent_handle test_resume_flags(lt::session& ses add_torrent_params p; std::vector rd = generate_resume_data(ti.get(), resume_file_prio); - + TORRENT_UNUSED(test_deprecated); #ifndef TORRENT_NO_DEPRECATE if (test_deprecated) { @@ -249,7 +249,7 @@ void test_piece_priorities(bool test_deprecated = false) TEST_EQUAL(prios[std::size_t(ti->num_pieces() - 1)], 0_pri); std::vector resume_data = write_resume_data_buf(ra->params); - + TORRENT_UNUSED(test_deprecated); #ifndef TORRENT_NO_DEPRECATE if (test_deprecated) { @@ -856,7 +856,7 @@ void test_zero_file_prio(bool test_deprecated = false) std::vector resume_data; bencode(back_inserter(resume_data), rd); - + TORRENT_UNUSED(test_deprecated); #ifndef TORRENT_NO_DEPRECATE if (test_deprecated) { diff --git a/test/test_storage.cpp b/test/test_storage.cpp index f1cfcb78a..4668e44a8 100644 --- a/test/test_storage.cpp +++ b/test/test_storage.cpp @@ -703,6 +703,7 @@ void test_fastresume(bool const test_deprecated) bencode(std::back_inserter(resume_data), resume); add_torrent_params p; + TORRENT_UNUSED(test_deprecated); #ifndef TORRENT_NO_DEPRECATE if (test_deprecated) { @@ -888,7 +889,7 @@ void test_rename_file_fastresume(bool test_deprecated) add_torrent_params p; std::vector resume_data; bencode(std::back_inserter(resume_data), resume_ent); - + TORRENT_UNUSED(test_deprecated); #ifndef TORRENT_NO_DEPRECATE if (test_deprecated) {