From 7ff692690b112aac4b67314f5d9d370671d71325 Mon Sep 17 00:00:00 2001 From: arvidn Date: Wed, 10 Oct 2018 16:52:38 +0200 Subject: [PATCH] fix warnings in tests and examples --- examples/client_test.cpp | 17 ++++++++--------- examples/connection_tester.cpp | 6 +++--- examples/upnp_test.cpp | 1 - test/CMakeLists.txt | 6 ++++++ 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/examples/client_test.cpp b/examples/client_test.cpp index f78ac6a3b..0273acd0c 100644 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -1238,11 +1238,11 @@ example alert_masks: // create directory for resume files #ifdef TORRENT_WINDOWS - int ret = _mkdir(path_append(save_path, ".resume").c_str()); + int mkdir_ret = _mkdir(path_append(save_path, ".resume").c_str()); #else - int ret = mkdir(path_append(save_path, ".resume").c_str(), 0777); + int mkdir_ret = mkdir(path_append(save_path, ".resume").c_str(), 0777); #endif - if (ret < 0 && errno != EEXIST) + if (mkdir_ret < 0 && errno != EEXIST) { std::fprintf(stderr, "failed to create resume file directory: (%d) %s\n" , errno, strerror(errno)); @@ -1455,8 +1455,8 @@ example alert_masks: set_keypress s(set_keypress::echo | set_keypress::canonical); #endif char response = 'n'; - int ret = std::scanf("%c", &response); - if (ret == 1 && response == 'y') + int scan_ret = std::scanf("%c", &response); + if (scan_ret == 1 && response == 'y') { // also delete the resume file std::string const rpath = resume_file(st.info_hash); @@ -1723,7 +1723,6 @@ COLUMN OPTIONS out += str; pos += 1; std::vector tr = h.trackers(); - lt::time_point now = lt::clock_type::now(); for (lt::announce_entry const& ae : h.trackers()) { auto best_ae = std::min_element(ae.endpoints.begin(), ae.endpoints.end() @@ -1744,9 +1743,9 @@ COLUMN OPTIONS if (print_matrix) { - int height = 0; - print(piece_matrix(s.pieces, terminal_width, &height).c_str()); - pos += height; + int height_out = 0; + print(piece_matrix(s.pieces, terminal_width, &height_out).c_str()); + pos += height_out; } if (print_downloads) diff --git a/examples/connection_tester.cpp b/examples/connection_tester.cpp index 72c1a0eed..f74156f46 100644 --- a/examples/connection_tester.cpp +++ b/examples/connection_tester.cpp @@ -793,13 +793,13 @@ void generate_torrent(std::vector& buf, int num_pieces, int num_files const std::int64_t total_size = std::int64_t(piece_size) * num_pieces; std::int64_t s = total_size; - int i = 0; + int file_index = 0; std::int64_t file_size = total_size / num_files; while (s > 0) { char b[100]; - std::snprintf(b, sizeof(b), "%s/stress_test%d", torrent_name, i); - ++i; + std::snprintf(b, sizeof(b), "%s/stress_test%d", torrent_name, file_index); + ++file_index; fs.add_file(b, std::min(s, file_size)); s -= file_size; file_size += 200; diff --git a/examples/upnp_test.cpp b/examples/upnp_test.cpp index 2bf611110..b1717e5ae 100644 --- a/examples/upnp_test.cpp +++ b/examples/upnp_test.cpp @@ -79,7 +79,6 @@ int main(int argc, char*[]) alert const* a = s.wait_for_alert(seconds(5)); if (a == nullptr) { - settings_pack p; p.set_bool(settings_pack::enable_upnp, false); p.set_bool(settings_pack::enable_natpmp, false); s.apply_settings(p); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 73faebc39..88b583588 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -17,6 +17,12 @@ add_library(test_common main.cpp test.cpp setup_transfer.cpp dht_server.cpp udp_ ) target_link_libraries(test_common PUBLIC torrent-rasterbar) target_compile_features(test_common PUBLIC cxx_std_11) +if (MSVC) + # C4127: conditional expression is constant + # C4309: 'conversion' : truncation of constant value + # C4310: cast truncates constant value + target_compile_options(test_common PUBLIC /wd4127 /wd4309 /wd4310 ) +endif() foreach(TARGET_SRC ${tests}) get_filename_component(TARGET ${TARGET_SRC} NAME_WE)