From c41ab094be766420e286d34f3fa7044f3a8477a4 Mon Sep 17 00:00:00 2001 From: Andrei Kurushin Date: Wed, 20 Apr 2016 07:45:32 +0300 Subject: [PATCH] fix release build with VS2015 UP2 compiler warnings for: examples, test, tools (#627) fix release build with VS2015 UP2 compiler warnings for: examples, test, tools --- examples/client_test.cpp | 8 +++--- examples/connection_tester.cpp | 6 ++--- examples/print.cpp | 14 +++++----- examples/print.hpp | 6 ++++- examples/session_view.cpp | 20 +++++++-------- include/libtorrent/torrent.hpp | 2 +- test/bittorrent_peer.cpp | 4 +-- test/print_alerts.cpp | 2 +- test/swarm_suite.cpp | 8 +++--- test/test_auto_unchoke.cpp | 6 ++--- test/test_bandwidth_limiter.cpp | 26 +++++++++---------- test/test_bitfield.cpp | 4 +-- test/test_buffer.cpp | 8 +++--- test/test_dht_storage.cpp | 2 +- test/test_fast_extension.cpp | 4 +-- test/test_fence.cpp | 25 ++++++++++-------- test/test_file_progress.cpp | 4 +-- test/test_file_storage.cpp | 2 +- test/test_http_connection.cpp | 6 ++--- test/test_lsd.cpp | 2 +- test/test_piece_picker.cpp | 6 ++--- test/test_privacy.cpp | 2 +- test/test_storage.cpp | 45 +++++++++++++++++---------------- test/test_utils.cpp | 2 +- test/web_seed_suite.cpp | 2 +- tools/fuzz_torrent.cpp | 4 +-- tools/parse_access_log.cpp | 4 +-- 27 files changed, 117 insertions(+), 107 deletions(-) diff --git a/examples/client_test.cpp b/examples/client_test.cpp index c4caf48c5..dacaa776c 100644 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -1122,7 +1122,7 @@ void print_piece(libtorrent::partial_piece_info* pp char chr = '+'; if (index >= 0) chr = (index < 10)?'0' + index:'A' + index - 10; - bool snubbed = index >= 0 ? peers[index].flags & peer_info::snubbed : false; + bool snubbed = index >= 0 ? ((peers[index].flags & peer_info::snubbed) != 0) : false; char const* color = ""; @@ -1321,7 +1321,7 @@ int main(int argc, char* argv[]) if (strcmp(value, "0") == 0 || strcmp(value, "1") == 0) { - settings.set_bool(sett_name, atoi(value)); + settings.set_bool(sett_name, atoi(value) != 0); } else { @@ -1849,7 +1849,7 @@ int main(int argc, char* argv[]) events.push_back(event_string); if (events.size() >= 20) events.pop_front(); } - } TORRENT_CATCH(std::exception& e) {} + } TORRENT_CATCH(std::exception& ) {} } alerts.clear(); @@ -2082,7 +2082,7 @@ int main(int argc, char* argv[]) } int progress = ti->files().file_size(i) > 0 - ?file_progress[i] * 1000 / ti->files().file_size(i):1000; + ? int(file_progress[i] * 1000 / ti->files().file_size(i)) : 1000; bool complete = file_progress[i] == ti->files().file_size(i); diff --git a/examples/connection_tester.cpp b/examples/connection_tester.cpp index b35a422d3..eac58f926 100644 --- a/examples/connection_tester.cpp +++ b/examples/connection_tester.cpp @@ -286,7 +286,7 @@ struct peer_conn // buffer is the full 68 byte handshake // look at the extension bits - fast_extension = ((char*)buffer)[27] & 4; + fast_extension = (((char*)buffer)[27] & 4) != 0; if (seed) { @@ -421,7 +421,7 @@ struct peer_conn end_time = clock_type::now(); char tmp[1024]; snprintf(tmp, sizeof(tmp), fmt, ec.message().c_str()); - int time = total_milliseconds(end_time - start_time); + int time = int(total_milliseconds(end_time - start_time)); if (time == 0) time = 1; float up = (boost::int64_t(blocks_sent) * 0x4000) / time / 1000.f; float down = (boost::int64_t(blocks_received) * 0x4000) / time / 1000.f; @@ -1079,7 +1079,7 @@ int main(int argc, char* argv[]) , end(conns.end()); i != end; ++i) { peer_conn* p = *i; - int time = total_milliseconds(p->end_time - p->start_time); + int time = int(total_milliseconds(p->end_time - p->start_time)); if (time == 0) time = 1; total_sent += p->blocks_sent; up += (boost::int64_t(p->blocks_sent) * 0x4000) / time / 1000.f; diff --git a/examples/print.cpp b/examples/print.cpp index f43e452fc..f28defca8 100644 --- a/examples/print.cpp +++ b/examples/print.cpp @@ -48,7 +48,7 @@ std::string to_string(int v, int width) return buf; } -std::string add_suffix(float val, char const* suffix) +std::string add_suffix_float(float val, char const* suffix) { if (val < 0.001f) { @@ -128,10 +128,10 @@ std::string const& progress_bar(int progress, int width, color_code c return bar; } -bool get_piece(libtorrent::bitfield const& p, int index) +int get_piece(libtorrent::bitfield const& p, int index) { - if (index < 0 || index >= p.size()) return false; - return p.get_bit(index); + if (index < 0 || index >= p.size()) return 0; + return p.get_bit(index) ? 1 : 0; } std::string const& piece_bar(libtorrent::bitfield const& p, int width) @@ -169,7 +169,9 @@ std::string const& piece_bar(libtorrent::bitfield const& p, int width) for (int k = int(piece); k < end; ++k, ++num_pieces) if (p[k]) ++num_have; int const c = int(std::ceil(num_have / float((std::max)(num_pieces, 1)) * (table_size - 1))); +#ifndef _WIN32 char buf[40]; +#endif color[i & 1] = c; #ifndef _WIN32 @@ -292,7 +294,7 @@ void set_cursor_pos(int x, int y) { #ifdef _WIN32 HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE); - COORD c = {x, y}; + COORD c = {SHORT(x), SHORT(y)}; SetConsoleCursorPosition(out, c); #else printf("\033[%d;%dH", y + 1, x + 1); @@ -322,7 +324,7 @@ void clear_rows(int y1, int y2) #ifdef _WIN32 HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE); - COORD c = {0, y1}; + COORD c = {0, SHORT(y1)}; SetConsoleCursorPosition(out, c); CONSOLE_SCREEN_BUFFER_INFO si; GetConsoleScreenBufferInfo(out, &si); diff --git a/examples/print.hpp b/examples/print.hpp index 09559f574..893b6fc20 100644 --- a/examples/print.hpp +++ b/examples/print.hpp @@ -21,7 +21,11 @@ char const* esc(char const* code); std::string to_string(int v, int width); -std::string add_suffix(float val, char const* suffix = 0); +std::string add_suffix_float(float val, char const* suffix); + +template std::string add_suffix(T val, char const* suffix = 0) { + return add_suffix_float(float(val), suffix); +} std::string color(std::string const& s, color_code c); diff --git a/examples/session_view.cpp b/examples/session_view.cpp index a2011d2b4..45402359e 100644 --- a/examples/session_view.cpp +++ b/examples/session_view.cpp @@ -70,10 +70,10 @@ void session_view::render() float seconds = (m_timestamp[0] - m_timestamp[1]) / 1000000.f; - int download_rate = (m_cnt[0][m_recv_payload_idx] - m_cnt[1][m_recv_payload_idx]) - / seconds; - int upload_rate = (m_cnt[0][m_sent_payload_idx] - m_cnt[1][m_sent_payload_idx]) - / seconds; + int download_rate = int((m_cnt[0][m_recv_payload_idx] - m_cnt[1][m_recv_payload_idx]) + / seconds); + int upload_rate = int((m_cnt[0][m_sent_payload_idx] - m_cnt[1][m_sent_payload_idx]) + / seconds); pos += snprintf(str, sizeof(str), "%s%s fail: %s down: %s (%s) " " bw queue: %s | %s conns: %3d unchoked: %2d / %2d " @@ -83,8 +83,8 @@ void session_view::render() , add_suffix(m_cnt[0][m_failed_bytes_idx]).c_str() , color(add_suffix(download_rate, "/s"), col_green).c_str() , color(add_suffix(m_cnt[0][m_recv_payload_idx]), col_green).c_str() - , color(to_string(m_cnt[0][m_limiter_up_queue_idx], 3), col_red).c_str() - , color(to_string(m_cnt[0][m_limiter_down_queue_idx], 3), col_green).c_str() + , color(to_string(int(m_cnt[0][m_limiter_up_queue_idx]), 3), col_red).c_str() + , color(to_string(int(m_cnt[0][m_limiter_down_queue_idx]), 3), col_green).c_str() , int(m_cnt[0][m_num_peers_idx]) , int(m_cnt[0][m_unchoked_idx]) , int(m_cnt[0][m_unchoke_slots_idx]) @@ -105,8 +105,8 @@ void session_view::render() , add_suffix(m_cnt[0][m_wasted_bytes_idx]).c_str() , color(add_suffix(upload_rate, "/s"), col_red).c_str() , color(add_suffix(m_cnt[0][m_sent_payload_idx]), col_red).c_str() - , color(to_string(m_cnt[0][m_queued_reads_idx], 3), col_red).c_str() - , color(to_string(m_cnt[0][m_queued_writes_idx], 3), col_green).c_str() + , color(to_string(int(m_cnt[0][m_queued_reads_idx]), 3), col_red).c_str() + , color(to_string(int(m_cnt[0][m_queued_writes_idx]), 3), col_green).c_str() , int((m_cnt[0][m_blocks_written_idx] - m_cnt[0][m_write_ops_idx]) * 100 / (std::max)(boost::uint64_t(1), m_cnt[0][m_blocks_written_idx])) , int(m_cnt[0][m_cache_hit_idx] * 100 @@ -159,7 +159,7 @@ void session_view::render() if (mru_size > 0) { pos += snprintf(str + pos, sizeof(str) - pos, "%s" - , progress_bar(m_cnt[0][m_mru_ghost_idx] * 1000 / mru_size + , progress_bar(int(m_cnt[0][m_mru_ghost_idx] * 1000 / mru_size) , mru_size * (m_width-8) / arc_size, col_yellow, '-', '#' , mru_caption, progress_invert).c_str()); } @@ -167,7 +167,7 @@ void session_view::render() if (mfu_size) { pos += snprintf(str + pos, sizeof(str) - pos, "%s" - , progress_bar(m_cnt[0][m_mfu_size_idx] * 1000 / mfu_size + , progress_bar(int(m_cnt[0][m_mfu_size_idx] * 1000 / mfu_size) , mfu_size * (m_width-8) / arc_size, col_green, '#', '-' , mfu_caption).c_str()); } diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 1f82592c7..565c6db72 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -1080,7 +1080,7 @@ namespace libtorrent // that are not private void lsd_announce(); - void update_last_upload() { m_last_upload = m_ses.session_time(); } + void update_last_upload() { m_last_upload = int16_t(m_ses.session_time()); } void set_apply_ip_filter(bool b); bool apply_ip_filter() const { return m_apply_ip_filter; } diff --git a/test/bittorrent_peer.cpp b/test/bittorrent_peer.cpp index 6d9954ce2..fc271ad09 100644 --- a/test/bittorrent_peer.cpp +++ b/test/bittorrent_peer.cpp @@ -124,7 +124,7 @@ void peer_conn::on_handshake2(error_code const& ec, size_t bytes_transferred) // buffer is the full 68 byte handshake // look at the extension bits - fast_extension = ((char*)buffer)[27] & 4; + fast_extension = (((char*)buffer)[27] & 4) != 0; if (m_mode == uploader) { @@ -262,7 +262,7 @@ void peer_conn::close(char const* fmt, error_code const& ec) end_time = clock_type::now(); char tmp[1024]; snprintf(tmp, sizeof(tmp), fmt, ec.message().c_str()); - int time = total_milliseconds(end_time - start_time); + int time = int(total_milliseconds(end_time - start_time)); if (time == 0) time = 1; float up = (boost::int64_t(blocks_sent) * 0x4000) / time / 1000.f; float down = (boost::int64_t(blocks_received) * 0x4000) / time / 1000.f; diff --git a/test/print_alerts.cpp b/test/print_alerts.cpp index 6d183f107..25bf79e3e 100644 --- a/test/print_alerts.cpp +++ b/test/print_alerts.cpp @@ -63,7 +63,7 @@ void print_alerts(libtorrent::session* ses, libtorrent::time_point start_time) } #endif lt::time_duration d = a->timestamp() - start_time; - boost::uint32_t millis = lt::duration_cast(d).count(); + boost::uint32_t millis = boost::uint32_t(lt::duration_cast(d).count()); printf("%4d.%03d: %-25s %s\n", millis / 1000, millis % 1000 , a->what() , a->message().c_str()); diff --git a/test/swarm_suite.cpp b/test/swarm_suite.cpp index 3be77faf7..2e89fd7ca 100644 --- a/test/swarm_suite.cpp +++ b/test/swarm_suite.cpp @@ -96,7 +96,7 @@ void test_swarm(int flags) int port = lt::random() % 100; char iface[50]; snprintf(iface, sizeof(iface), "0.0.0.0:480%02d", port); - pack.set_int(settings_pack::upload_rate_limit, rate_limit); + pack.set_int(settings_pack::upload_rate_limit, int(rate_limit)); pack.set_str(settings_pack::listen_interfaces, iface); pack.set_int(settings_pack::max_retry_port_bind, 1000); @@ -107,8 +107,8 @@ void test_swarm(int flags) snprintf(iface, sizeof(iface), "0.0.0.0:490%02d", port); pack.set_str(settings_pack::listen_interfaces, iface); - pack.set_int(settings_pack::download_rate_limit, rate_limit / 2); - pack.set_int(settings_pack::upload_rate_limit, rate_limit); + pack.set_int(settings_pack::download_rate_limit, int(rate_limit / 2)); + pack.set_int(settings_pack::upload_rate_limit, int(rate_limit)); lt::session ses2(pack); snprintf(iface, sizeof(iface), "0.0.0.0:500%02d", port); @@ -166,7 +166,7 @@ void test_swarm(int flags) ++count_dl_rates3; } - print_ses_rate(i, &st1, &st2, &st3); + print_ses_rate(float(i), &st1, &st2, &st3); if (st2.is_seeding && st3.is_seeding) break; test_sleep(1000); diff --git a/test/test_auto_unchoke.cpp b/test/test_auto_unchoke.cpp index 0077f195f..9e731875d 100644 --- a/test/test_auto_unchoke.cpp +++ b/test/test_auto_unchoke.cpp @@ -67,7 +67,7 @@ void test_swarm() pack.set_int(settings_pack::alert_mask, alert::all_categories); pack.set_bool(settings_pack::allow_multiple_connections_per_ip, true); pack.set_int(settings_pack::choking_algorithm, settings_pack::rate_based_choker); - pack.set_int(settings_pack::upload_rate_limit, rate_limit); + pack.set_int(settings_pack::upload_rate_limit, int(rate_limit)); pack.set_int(settings_pack::unchoke_slots_limit, 1); pack.set_int(settings_pack::max_retry_port_bind, 900); pack.set_str(settings_pack::listen_interfaces, "0.0.0.0:48010"); @@ -80,8 +80,8 @@ void test_swarm() lt::session ses1(pack); - pack.set_int(settings_pack::upload_rate_limit, rate_limit / 10); - pack.set_int(settings_pack::download_rate_limit, rate_limit / 5); + pack.set_int(settings_pack::upload_rate_limit, int(rate_limit / 10)); + pack.set_int(settings_pack::download_rate_limit, int(rate_limit / 5)); pack.set_int(settings_pack::unchoke_slots_limit, 0); pack.set_int(settings_pack::choking_algorithm, settings_pack::fixed_slots_choker); pack.set_str(settings_pack::listen_interfaces, "0.0.0.0:49010"); diff --git a/test/test_bandwidth_limiter.cpp b/test/test_bandwidth_limiter.cpp index 091600b1e..dc388b2fb 100644 --- a/test/test_bandwidth_limiter.cpp +++ b/test/test_bandwidth_limiter.cpp @@ -205,12 +205,12 @@ void test_equal_connections(int num, int limit) std::cerr << (*i)->m_quota / sample_time << " target: " << (limit / num) << " eps: " << err << std::endl; - TEST_CHECK(close_to((*i)->m_quota / sample_time, limit / num, err)); + TEST_CHECK(close_to((*i)->m_quota / sample_time, float(limit) / num, err)); } sum /= sample_time; std::cerr << "sum: " << sum << " target: " << limit << std::endl; TEST_CHECK(sum > 0); - TEST_CHECK(close_to(sum, limit, 50)); + TEST_CHECK(close_to(sum, float(limit), 50)); } void test_connections_variable_rate(int num, int limit, int torrent_limit) @@ -246,12 +246,12 @@ void test_connections_variable_rate(int num, int limit, int torrent_limit) std::cerr << (*i)->m_quota / sample_time << " target: " << limit << " eps: " << err << std::endl; - TEST_CHECK(close_to((*i)->m_quota / sample_time, limit, err)); + TEST_CHECK(close_to((*i)->m_quota / sample_time, float(limit), err)); } sum /= sample_time; std::cerr << "sum: " << sum << " target: " << (limit * num) << std::endl; TEST_CHECK(sum > 0); - TEST_CHECK(close_to(sum, limit * num, limit * 0.3f * num)); + TEST_CHECK(close_to(sum, float(limit) * num, limit * 0.3f * num)); } void test_single_peer(int limit, bool torrent_limit) @@ -279,7 +279,7 @@ void test_single_peer(int limit, bool torrent_limit) sum /= sample_time; std::cerr << sum << " target: " << limit << std::endl; TEST_CHECK(sum > 0); - TEST_CHECK(close_to(sum, limit, 1000)); + TEST_CHECK(close_to(sum, float(limit), 1000)); } void test_torrents(int num, int limit1, int limit2, int global_limit) @@ -320,7 +320,7 @@ void test_torrents(int num, int limit1, int limit2, int global_limit) sum /= sample_time; std::cerr << sum << " target: " << limit1 << std::endl; TEST_CHECK(sum > 0); - TEST_CHECK(close_to(sum, limit1, 1000)); + TEST_CHECK(close_to(sum, float(limit1), 1000)); sum = 0.f; for (connections_t::iterator i = v2.begin() @@ -331,7 +331,7 @@ void test_torrents(int num, int limit1, int limit2, int global_limit) sum /= sample_time; std::cerr << sum << " target: " << limit2 << std::endl; TEST_CHECK(sum > 0); - TEST_CHECK(close_to(sum, limit2, 1000)); + TEST_CHECK(close_to(sum, float(limit2), 1000)); } void test_torrents_variable_rate(int num, int limit, int global_limit) @@ -370,7 +370,7 @@ void test_torrents_variable_rate(int num, int limit, int global_limit) sum /= sample_time; std::cerr << sum << " target: " << limit << std::endl; TEST_CHECK(sum > 0); - TEST_CHECK(close_to(sum, limit, 1000)); + TEST_CHECK(close_to(sum, float(limit), 1000)); sum = 0.f; for (connections_t::iterator i = v2.begin() @@ -381,7 +381,7 @@ void test_torrents_variable_rate(int num, int limit, int global_limit) sum /= sample_time; std::cerr << sum << " target: " << limit << std::endl; TEST_CHECK(sum > 0); - TEST_CHECK(close_to(sum, limit, 1000)); + TEST_CHECK(close_to(sum, float(limit), 1000)); } void test_peer_priority(int limit, bool torrent_limit) @@ -414,11 +414,11 @@ void test_peer_priority(int limit, bool torrent_limit) sum /= sample_time; std::cerr << sum << " target: " << limit << std::endl; TEST_CHECK(sum > 0); - TEST_CHECK(close_to(sum, limit, 50)); + TEST_CHECK(close_to(sum, float(limit), 50)); std::cerr << "non-prioritized rate: " << p->m_quota / sample_time << " target: " << (limit / 200 / 10) << std::endl; - TEST_CHECK(close_to(p->m_quota / sample_time, limit / 200 / 10, 5)); + TEST_CHECK(close_to(p->m_quota / sample_time, float(limit) / 200 / 10, 5)); } void test_no_starvation(int limit) @@ -450,11 +450,11 @@ void test_no_starvation(int limit) sum /= sample_time; std::cerr << sum << " target: " << limit << std::endl; TEST_CHECK(sum > 0); - TEST_CHECK(close_to(sum, limit, 50)); + TEST_CHECK(close_to(sum, float(limit), 50)); std::cerr << "non-prioritized rate: " << p->m_quota / sample_time << " target: " << (limit / 200 / num_peers) << std::endl; - TEST_CHECK(close_to(p->m_quota / sample_time, limit / 200 / num_peers, 5)); + TEST_CHECK(close_to(p->m_quota / sample_time, float(limit) / 200 / num_peers, 5)); } TORRENT_TEST(equal_connection) diff --git a/test/test_bitfield.cpp b/test/test_bitfield.cpp index f2a548e44..64f1b1e9a 100644 --- a/test/test_bitfield.cpp +++ b/test/test_bitfield.cpp @@ -171,7 +171,7 @@ TORRENT_TEST(bitfield) for (int i = 0; i < 4; ++i) { - b[i] = 0xc0; + b[i] = char(0xc0); test1.assign(b + i, 2); print_bitfield(test1); TEST_EQUAL(test1.count(), 2); @@ -181,7 +181,7 @@ TORRENT_TEST(bitfield) for (int i = 0; i < 4; ++i) { memset(b + i, 0xff, 5); - b[i + 5] = 0xc0; + b[i + 5] = char(0xc0); test1.assign(b + i, 32 + 8 + 2); print_bitfield(test1); TEST_EQUAL(test1.count(), 32 + 8 + 2); diff --git a/test/test_buffer.cpp b/test/test_buffer.cpp index d7a9db522..df191bd5a 100644 --- a/test/test_buffer.cpp +++ b/test/test_buffer.cpp @@ -242,7 +242,7 @@ TORRENT_TEST(chained_buffer) TEST_CHECK(!b.empty()); TEST_CHECK(b.space_in_last_buffer() == 512 - 6); - bool ret = b.append(data, 6); + bool ret = b.append(data, 6) != NULL; TEST_CHECK(ret == true); TEST_CHECK(b.capacity() == 512); @@ -251,7 +251,7 @@ TORRENT_TEST(chained_buffer) TEST_CHECK(b.space_in_last_buffer() == 512 - 12); char data2[1024]; - ret = b.append(data2, 1024); + ret = b.append(data2, 1024) != NULL; TEST_CHECK(ret == false); @@ -300,11 +300,11 @@ TORRENT_TEST(chained_buffer) b.append_buffer(b4, 20, 12, &free_buffer, (void*)0x1337); TEST_CHECK(b.space_in_last_buffer() == 8); - ret = b.append(data, 6); + ret = b.append(data, 6) != NULL; TEST_CHECK(ret == true); TEST_CHECK(b.space_in_last_buffer() == 2); std::cout << b.space_in_last_buffer() << std::endl; - ret = b.append(data, 2); + ret = b.append(data, 2) != NULL; TEST_CHECK(ret == true); TEST_CHECK(b.space_in_last_buffer() == 0); std::cout << b.space_in_last_buffer() << std::endl; diff --git a/test/test_dht_storage.cpp b/test/test_dht_storage.cpp index dba79c27b..4246e76a4 100644 --- a/test/test_dht_storage.cpp +++ b/test/test_dht_storage.cpp @@ -64,7 +64,7 @@ namespace dht_settings sett; sett.max_torrents = 2; sett.max_dht_items = 2; - sett.item_lifetime = seconds(120 * 60).count(); + sett.item_lifetime = int(seconds(120 * 60).count()); return sett; } diff --git a/test/test_fast_extension.cpp b/test/test_fast_extension.cpp index 249eb78f7..e8e1aecf4 100644 --- a/test/test_fast_extension.cpp +++ b/test/test_fast_extension.cpp @@ -759,7 +759,7 @@ TORRENT_TEST(dont_have) TEST_CHECK(dont_have); if (!dont_have) return; - lt_dont_have = dont_have.int_value(); + lt_dont_have = int(dont_have.int_value()); } print_session_log(*ses); @@ -822,7 +822,7 @@ TORRENT_TEST(invalid_metadata_request) extensions = read_extension_handshake(s, recv_buffer, sizeof(recv_buffer)); - int ut_metadata = extensions["m"]["ut_metadata"].integer(); + int ut_metadata = int(extensions["m"]["ut_metadata"].integer()); log("ut_metadata: %d", ut_metadata); diff --git a/test/test_fence.cpp b/test/test_fence.cpp index 24445d504..502512c29 100644 --- a/test/test_fence.cpp +++ b/test/test_fence.cpp @@ -14,12 +14,13 @@ TORRENT_TEST(empty_fence) disk_io_job test_job[10]; // issue 5 jobs. None of them should be blocked by a fence - int ret = 0; + int ret_int = 0; + bool ret = false; // add a fence job - ret = fence.raise_fence(&test_job[5], &test_job[6], cnt); + ret_int = fence.raise_fence(&test_job[5], &test_job[6], cnt); // since we don't have any outstanding jobs // we need to post this job - TEST_CHECK(ret == disk_job_fence::fence_post_fence); + TEST_CHECK(ret_int == disk_job_fence::fence_post_fence); ret = fence.is_blocked(&test_job[7]); TEST_CHECK(ret == true); @@ -50,6 +51,7 @@ TORRENT_TEST(job_fence) disk_io_job test_job[10]; // issue 5 jobs. None of them should be blocked by a fence + int ret_int = 0; bool ret = false; TEST_CHECK(fence.num_outstanding_jobs() == 0); ret = fence.is_blocked(&test_job[0]); @@ -68,10 +70,10 @@ TORRENT_TEST(job_fence) TEST_CHECK(fence.num_blocked() == 0); // add a fence job - ret = fence.raise_fence(&test_job[5], &test_job[6], cnt); + ret_int = fence.raise_fence(&test_job[5], &test_job[6], cnt); // since we have outstanding jobs, no need // to post anything - TEST_CHECK(ret == disk_job_fence::fence_post_flush); + TEST_CHECK(ret_int == disk_job_fence::fence_post_flush); ret = fence.is_blocked(&test_job[7]); TEST_CHECK(ret == true); @@ -123,7 +125,8 @@ TORRENT_TEST(double_fence) disk_io_job test_job[10]; // issue 5 jobs. None of them should be blocked by a fence - int ret = 0; + int ret_int = 0; + bool ret = false; TEST_CHECK(fence.num_outstanding_jobs() == 0); ret = fence.is_blocked(&test_job[0]); TEST_CHECK(ret == false); @@ -141,16 +144,16 @@ TORRENT_TEST(double_fence) TEST_CHECK(fence.num_blocked() == 0); // add two fence jobs - ret = fence.raise_fence(&test_job[5], &test_job[6], cnt); + ret_int = fence.raise_fence(&test_job[5], &test_job[6], cnt); // since we have outstanding jobs, no need // to post anything - TEST_CHECK(ret == disk_job_fence::fence_post_flush); + TEST_CHECK(ret_int == disk_job_fence::fence_post_flush); - ret = fence.raise_fence(&test_job[7], &test_job[8], cnt); + ret_int = fence.raise_fence(&test_job[7], &test_job[8], cnt); // since we have outstanding jobs, no need // to post anything - TEST_CHECK(ret == disk_job_fence::fence_post_none); - fprintf(stderr, "ret: %d\n", ret); + TEST_CHECK(ret_int == disk_job_fence::fence_post_none); + fprintf(stderr, "ret: %d\n", ret_int); ret = fence.is_blocked(&test_job[9]); TEST_CHECK(ret == true); diff --git a/test/test_file_progress.cpp b/test/test_file_progress.cpp index da6e81298..9250bfc31 100644 --- a/test/test_file_progress.cpp +++ b/test/test_file_progress.cpp @@ -52,7 +52,7 @@ TORRENT_TEST(init) fs.add_file("torrent/6", 100000); fs.add_file("torrent/7", 30); fs.set_piece_length(piece_size); - fs.set_num_pieces((fs.total_size() + piece_size - 1) / piece_size); + fs.set_num_pieces((int(fs.total_size()) + piece_size - 1) / piece_size); for (int idx = 0; idx < fs.num_pieces(); ++idx) { @@ -84,7 +84,7 @@ TORRENT_TEST(init2) fs.add_file("torrent/1", 100000); fs.add_file("torrent/2", 10); fs.set_piece_length(piece_size); - fs.set_num_pieces((fs.total_size() + piece_size - 1) / piece_size); + fs.set_num_pieces((int(fs.total_size()) + piece_size - 1) / piece_size); for (int idx = 0; idx < fs.num_pieces(); ++idx) { diff --git a/test/test_file_storage.cpp b/test/test_file_storage.cpp index ccb4b0ac7..260904f54 100644 --- a/test/test_file_storage.cpp +++ b/test/test_file_storage.cpp @@ -46,7 +46,7 @@ void setup_test_storage(file_storage& st) st.add_file(combine_path("test", combine_path("c", "b")), 40000); st.set_piece_length(0x4000); - st.set_num_pieces((st.total_size() + st.piece_length() - 1) / 0x4000); + st.set_num_pieces((int(st.total_size()) + st.piece_length() - 1) / 0x4000); TEST_EQUAL(st.file_name(0), "a"); TEST_EQUAL(st.file_name(1), "b"); diff --git a/test/test_http_connection.cpp b/test/test_http_connection.cpp index e5de2bac6..f52aaa3f8 100644 --- a/test/test_http_connection.cpp +++ b/test/test_http_connection.cpp @@ -143,7 +143,7 @@ void run_test(std::string const& url, int size, int status, int connected void write_test_file() { - std::srand(std::time(0)); + std::srand(unsigned(std::time(0))); std::generate(data_buffer, data_buffer + sizeof(data_buffer), &std::rand); error_code ec; file test_file("test_file", file::write_only, ec); @@ -171,8 +171,8 @@ void run_suite(std::string const& protocol // starting the web server will also generate test_file.gz (from test_file) // so it has to happen after we write test_file int port = start_web_server(protocol == "https" - , flags & flag_chunked_encoding - , flags & flag_keepalive); + , (flags & flag_chunked_encoding) != 0 + , (flags & flag_keepalive) != 0); aux::proxy_settings ps; ps.hostname = "127.0.0.1"; diff --git a/test/test_lsd.cpp b/test/test_lsd.cpp index f550aec6f..09d106c8c 100644 --- a/test/test_lsd.cpp +++ b/test/test_lsd.cpp @@ -80,7 +80,7 @@ void test_lsd() torrent_status st1 = tor1.status(); torrent_status st2 = tor2.status(); - print_ses_rate(i, &st1, &st2); + print_ses_rate(float(i), &st1, &st2); if (st2.is_seeding /*&& st3.is_seeding*/) break; test_sleep(1000); diff --git a/test/test_piece_picker.cpp b/test/test_piece_picker.cpp index e3671d5d9..91d94cb90 100644 --- a/test/test_piece_picker.cpp +++ b/test/test_piece_picker.cpp @@ -130,7 +130,7 @@ boost::shared_ptr setup_picker( ++counter; bool ret = p->mark_as_downloading(piece_block(i, j), tmp_peer); TEST_CHECK(ret == true); - TEST_CHECK(p->is_requested(piece_block(i, j)) == bool(blocks & (1 << j))); + TEST_CHECK(p->is_requested(piece_block(i, j)) == ((blocks & (1 << j)) != 0)); p->mark_as_writing(piece_block(i, j), tmp_peer); TEST_CHECK(!p->is_finished(piece_block(i, j))); // trying to mark a block as requested after it has been completed @@ -139,8 +139,8 @@ boost::shared_ptr setup_picker( TEST_CHECK(ret == false); p->mark_as_finished(piece_block(i, j), tmp_peer); - TEST_CHECK(p->is_downloaded(piece_block(i, j)) == bool(blocks & (1 << j))); - TEST_CHECK(p->is_finished(piece_block(i, j)) == bool(blocks & (1 << j))); + TEST_CHECK(p->is_downloaded(piece_block(i, j)) == ((blocks & (1 << j)) != 0)); + TEST_CHECK(p->is_finished(piece_block(i, j)) == ((blocks & (1 << j)) != 0)); } piece_picker::downloading_piece st; diff --git a/test/test_privacy.cpp b/test/test_privacy.cpp index 776c2f72d..012eb602e 100644 --- a/test/test_privacy.cpp +++ b/test/test_privacy.cpp @@ -194,7 +194,7 @@ session_proxy test_proxy(settings_pack::proxy_type_t proxy_type, int flags) } else { - TEST_EQUAL(num_udp_announces(), prev_udp_announces + bool(flags & expect_udp_connection)); + TEST_EQUAL(num_udp_announces(), prev_udp_announces + ((flags & expect_udp_connection) != 0 ? 1 : 0)); } if (flags & expect_possible_udp_connection) diff --git a/test/test_storage.cpp b/test/test_storage.cpp index 0d6d83315..4e1b3acb3 100644 --- a/test/test_storage.cpp +++ b/test/test_storage.cpp @@ -506,7 +506,7 @@ void run_test(bool unbuffered) fs.add_file("temp_storage/test4.tmp", 0); fs.add_file("temp_storage/test5.tmp", 3253); fs.add_file("temp_storage/test6.tmp", 841); - const int last_file_size = 4 * piece_size - fs.total_size(); + const int last_file_size = 4 * piece_size - int(fs.total_size()); fs.add_file("temp_storage/test7.tmp", last_file_size); // File layout @@ -1016,7 +1016,7 @@ file_storage make_fs() fs.add_file(combine_path("readwritev", "3"), 81); fs.add_file(combine_path("readwritev", "4"), 6561); fs.set_piece_length(0x1000); - fs.set_num_pieces((fs.total_size() + 0xfff) / 0x1000); + fs.set_num_pieces(int((fs.total_size() + 0xfff) / 0x1000)); return fs; } @@ -1024,9 +1024,10 @@ struct test_fileop : fileop { test_fileop(int stripe_size) : m_stripe_size(stripe_size) {} - int file_op(int file_index, boost::int64_t file_offset, int size + int file_op(int const file_index, boost::int64_t const file_offset, int const size , file::iovec_t const* bufs, storage_error& ec) { + size_t offset = size_t(file_offset); if (file_index >= int(m_file_data.size())) { m_file_data.resize(file_index + 1); @@ -1036,18 +1037,18 @@ struct test_fileop : fileop std::vector& file = m_file_data[file_index]; - if (file_offset + write_size > int(file.size())) + if (offset + write_size > file.size()) { - file.resize(file_offset + write_size); + file.resize(offset + write_size); } int left = write_size; while (left > 0) { const int copy_size = (std::min)(left, int(bufs->iov_len)); - memcpy(&file[file_offset], bufs->iov_base, copy_size); + memcpy(&file[offset], bufs->iov_base, copy_size); ++bufs; - file_offset += copy_size; + offset += copy_size; left -= copy_size; } return write_size; @@ -1062,21 +1063,21 @@ struct test_read_fileop : fileop // EOF after size bytes read test_read_fileop(int size) : m_size(size), m_counter(0) {} - int file_op(int file_index, boost::int64_t file_offset, int size + int file_op(int const file_index, boost::int64_t const file_offset, int const size , file::iovec_t const* bufs, storage_error& ec) { - size = (std::min)(m_size, size); - const int read = size; - while (size > 0) + int local_size = (std::min)(m_size, size); + const int read = local_size; + while (local_size > 0) { unsigned char* p = (unsigned char*)bufs->iov_base; - const int len = (std::min)(int(bufs->iov_len), size); + const int len = (std::min)(int(bufs->iov_len), local_size); for (int i = 0; i < len; ++i) { p[i] = m_counter & 0xff; ++m_counter; } - size -= len; + local_size -= len; m_size -= len; ++bufs; } @@ -1093,7 +1094,7 @@ struct test_error_fileop : fileop test_error_fileop(int error_file) : m_error_file(error_file) {} - int file_op(int file_index, boost::int64_t file_offset, int size + int file_op(int const file_index, boost::int64_t const file_offset, int const size , file::iovec_t const* bufs, storage_error& ec) { if (m_error_file == file_index) @@ -1137,8 +1138,8 @@ TORRENT_TEST(readwritev_stripe_1) TEST_CHECK(bufs_size(iov, num_bufs) >= fs.total_size()); file::iovec_t iov2[num_bufs]; - copy_bufs(iov, fs.total_size(), iov2); - int num_bufs2 = count_bufs(iov2, fs.total_size()); + copy_bufs(iov, int(fs.total_size()), iov2); + int num_bufs2 = count_bufs(iov2, int(fs.total_size())); TEST_CHECK(num_bufs2 <= num_bufs); int ret = readwritev(fs, iov2, 0, 0, num_bufs2, fop, ec); @@ -1164,7 +1165,7 @@ TORRENT_TEST(readwritev_single_buffer) test_fileop fop(10000000); storage_error ec; - std::vector buf(fs.total_size()); + std::vector buf(size_t(fs.total_size())); file::iovec_t iov = { &buf[0], buf.size() }; fill_pattern(&iov, 1); @@ -1189,7 +1190,7 @@ TORRENT_TEST(readwritev_read) test_read_fileop fop(10000000); storage_error ec; - std::vector buf(fs.total_size()); + std::vector buf(size_t(fs.total_size())); file::iovec_t iov = { &buf[0], buf.size() }; // read everything @@ -1205,7 +1206,7 @@ TORRENT_TEST(readwritev_read_short) test_read_fileop fop(100); storage_error ec; - std::vector buf(fs.total_size()); + std::vector buf(size_t(fs.total_size())); file::iovec_t iov = { &buf[0] , static_cast(fs.total_size()) }; @@ -1225,7 +1226,7 @@ TORRENT_TEST(readwritev_error) test_error_fileop fop(2); storage_error ec; - std::vector buf(fs.total_size()); + std::vector buf(size_t(fs.total_size())); file::iovec_t iov = { &buf[0] , static_cast(fs.total_size()) }; @@ -1248,11 +1249,11 @@ TORRENT_TEST(readwritev_zero_size_files) fs.add_file(combine_path("readwritev", "4"), 0); fs.add_file(combine_path("readwritev", "5"), 6561); fs.set_piece_length(0x1000); - fs.set_num_pieces((fs.total_size() + 0xfff) / 0x1000); + fs.set_num_pieces(int((fs.total_size() + 0xfff) / 0x1000)); test_read_fileop fop(10000000); storage_error ec; - std::vector buf(fs.total_size()); + std::vector buf(size_t(fs.total_size())); file::iovec_t iov = { &buf[0] , static_cast(fs.total_size()) }; diff --git a/test/test_utils.cpp b/test/test_utils.cpp index 51963472f..c299805b9 100644 --- a/test/test_utils.cpp +++ b/test/test_utils.cpp @@ -39,7 +39,7 @@ namespace libtorrent { static const time_point start = clock_type::now(); static char ret[200]; - int t = total_milliseconds(clock_type::now() - start); + int t = int(total_milliseconds(clock_type::now() - start)); int h = t / 1000 / 60 / 60; t -= h * 60 * 60 * 1000; int m = t / 1000 / 60; diff --git a/test/web_seed_suite.cpp b/test/web_seed_suite.cpp index b5324db81..393f19946 100644 --- a/test/web_seed_suite.cpp +++ b/test/web_seed_suite.cpp @@ -154,7 +154,7 @@ void test_transfer(lt::session& ses, boost::shared_ptr torrent_fil for (int i = 0; i < fs.num_files(); ++i) { if (fs.file_flags(i) & file_storage::flag_pad_file) - pad_file_size += fs.file_size(i); + pad_file_size += int(fs.file_size(i)); } peer_disconnects = 0; diff --git a/tools/fuzz_torrent.cpp b/tools/fuzz_torrent.cpp index 1a5bb9e61..12651576a 100644 --- a/tools/fuzz_torrent.cpp +++ b/tools/fuzz_torrent.cpp @@ -130,13 +130,13 @@ void print_string(std::string& output, std::string str) } const bool random_string = g_seed > 0 && g_seed <= 1000; - const int str_seed = g_seed - 1; + const int str_seed = int(g_seed) - 1; g_seed -= 1000; if (random_string) { static mt19937 random_engine(str_seed); uniform_int_distribution d(0, 255); - for (int i = 0; i < str.size(); ++i) + for (int i = 0; i < int(str.size()); ++i) str[i] = d(random_engine); print_ascii_number(output, str.size()); diff --git a/tools/parse_access_log.cpp b/tools/parse_access_log.cpp index 67e97e848..435853fb8 100644 --- a/tools/parse_access_log.cpp +++ b/tools/parse_access_log.cpp @@ -96,8 +96,8 @@ int main(int argc, char* argv[]) if (first_timestamp == 0) first_timestamp = op.timestamp; - bool write = op.event & 1; - bool complete = op.event & 2; + bool write = (op.event & 1) != 0; + bool complete = (op.event & 2) != 0; FILE* out_file = 0; if (complete) {