fix warnings in tests and examples

This commit is contained in:
arvidn 2018-10-10 16:52:38 +02:00 committed by Arvid Norberg
parent 8e8489c6dc
commit 7ff692690b
4 changed files with 17 additions and 13 deletions

View File

@ -1238,11 +1238,11 @@ example alert_masks:
// create directory for resume files // create directory for resume files
#ifdef TORRENT_WINDOWS #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 #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 #endif
if (ret < 0 && errno != EEXIST) if (mkdir_ret < 0 && errno != EEXIST)
{ {
std::fprintf(stderr, "failed to create resume file directory: (%d) %s\n" std::fprintf(stderr, "failed to create resume file directory: (%d) %s\n"
, errno, strerror(errno)); , errno, strerror(errno));
@ -1455,8 +1455,8 @@ example alert_masks:
set_keypress s(set_keypress::echo | set_keypress::canonical); set_keypress s(set_keypress::echo | set_keypress::canonical);
#endif #endif
char response = 'n'; char response = 'n';
int ret = std::scanf("%c", &response); int scan_ret = std::scanf("%c", &response);
if (ret == 1 && response == 'y') if (scan_ret == 1 && response == 'y')
{ {
// also delete the resume file // also delete the resume file
std::string const rpath = resume_file(st.info_hash); std::string const rpath = resume_file(st.info_hash);
@ -1723,7 +1723,6 @@ COLUMN OPTIONS
out += str; out += str;
pos += 1; pos += 1;
std::vector<lt::announce_entry> tr = h.trackers(); std::vector<lt::announce_entry> tr = h.trackers();
lt::time_point now = lt::clock_type::now();
for (lt::announce_entry const& ae : h.trackers()) for (lt::announce_entry const& ae : h.trackers())
{ {
auto best_ae = std::min_element(ae.endpoints.begin(), ae.endpoints.end() auto best_ae = std::min_element(ae.endpoints.begin(), ae.endpoints.end()
@ -1744,9 +1743,9 @@ COLUMN OPTIONS
if (print_matrix) if (print_matrix)
{ {
int height = 0; int height_out = 0;
print(piece_matrix(s.pieces, terminal_width, &height).c_str()); print(piece_matrix(s.pieces, terminal_width, &height_out).c_str());
pos += height; pos += height_out;
} }
if (print_downloads) if (print_downloads)

View File

@ -793,13 +793,13 @@ void generate_torrent(std::vector<char>& buf, int num_pieces, int num_files
const std::int64_t total_size = std::int64_t(piece_size) * num_pieces; const std::int64_t total_size = std::int64_t(piece_size) * num_pieces;
std::int64_t s = total_size; std::int64_t s = total_size;
int i = 0; int file_index = 0;
std::int64_t file_size = total_size / num_files; std::int64_t file_size = total_size / num_files;
while (s > 0) while (s > 0)
{ {
char b[100]; char b[100];
std::snprintf(b, sizeof(b), "%s/stress_test%d", torrent_name, i); std::snprintf(b, sizeof(b), "%s/stress_test%d", torrent_name, file_index);
++i; ++file_index;
fs.add_file(b, std::min(s, file_size)); fs.add_file(b, std::min(s, file_size));
s -= file_size; s -= file_size;
file_size += 200; file_size += 200;

View File

@ -79,7 +79,6 @@ int main(int argc, char*[])
alert const* a = s.wait_for_alert(seconds(5)); alert const* a = s.wait_for_alert(seconds(5));
if (a == nullptr) if (a == nullptr)
{ {
settings_pack p;
p.set_bool(settings_pack::enable_upnp, false); p.set_bool(settings_pack::enable_upnp, false);
p.set_bool(settings_pack::enable_natpmp, false); p.set_bool(settings_pack::enable_natpmp, false);
s.apply_settings(p); s.apply_settings(p);

View File

@ -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_link_libraries(test_common PUBLIC torrent-rasterbar)
target_compile_features(test_common PUBLIC cxx_std_11) 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}) foreach(TARGET_SRC ${tests})
get_filename_component(TARGET ${TARGET_SRC} NAME_WE) get_filename_component(TARGET ${TARGET_SRC} NAME_WE)