From 12c9d3de2614708a32baae597bfacbbc3398fb47 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 16 May 2015 18:35:47 +0000 Subject: [PATCH] fix more warnings --- Jamfile | 6 ++- include/libtorrent/aux_/session_impl.hpp | 8 ---- include/libtorrent/aux_/time.hpp | 2 + include/libtorrent/torrent_info.hpp | 5 ++- src/peer_connection.cpp | 2 +- src/session_impl.cpp | 17 ++----- src/time.cpp | 7 ++- src/torrent_info.cpp | 3 +- src/utf8.cpp | 56 ++++++++++++++---------- test/test_torrent_info.cpp | 39 +++++++---------- 10 files changed, 74 insertions(+), 71 deletions(-) diff --git a/Jamfile b/Jamfile index c485bc807..6d8e58f54 100755 --- a/Jamfile +++ b/Jamfile @@ -247,7 +247,11 @@ rule warnings ( properties * ) result += -Wno-documentation-unknown-command ; result += -Wno-disabled-macro-expansion ; -# enable these warnings again, once the other ones are dealt with +# in C++98 mode there's no way to silence this warning +# in the code (without final) + result += -Wno-non-virtual-dtor ; + +# enable these warnings again, once the other ones are delt with result += -Wno-weak-vtables ; result += -Wno-sign-compare ; result += -Wno-sign-conversion ; diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index b185ecba7..1501e8821 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -152,13 +152,6 @@ namespace libtorrent struct tracker_logger; #endif - // used to initialize the g_current_time before - // anything else - struct initialize_timer - { - initialize_timer(); - }; - TORRENT_EXPORT std::pair settings_map(); // this is the link between the main thread and the @@ -167,7 +160,6 @@ namespace libtorrent : session_interface , dht::dht_observer , boost::noncopyable - , initialize_timer , udp_socket_observer , uncork_interface , single_threaded diff --git a/include/libtorrent/aux_/time.hpp b/include/libtorrent/aux_/time.hpp index 0ce881851..12c278f99 100644 --- a/include/libtorrent/aux_/time.hpp +++ b/include/libtorrent/aux_/time.hpp @@ -44,6 +44,8 @@ namespace libtorrent { namespace aux // resolution of this timer is about 100 ms. time_point const& time_now(); + void update_time_now(); + } } #endif diff --git a/include/libtorrent/torrent_info.hpp b/include/libtorrent/torrent_info.hpp index 13e9ed36c..bb700a35e 100644 --- a/include/libtorrent/torrent_info.hpp +++ b/include/libtorrent/torrent_info.hpp @@ -59,9 +59,12 @@ namespace libtorrent class peer_connection; namespace aux { struct session_settings; } - // exposed for the unit test + + // internal, exposed for the unit test TORRENT_EXTRA_EXPORT void sanitize_append_path_element(std::string& path , char const* element, int element_len); + TORRENT_EXTRA_EXPORT bool verify_encoding(std::string& target + , bool fix_paths = false); enum { diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 06eafbe54..3c544afc5 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -94,7 +94,7 @@ namespace libtorrent enum { // the limits of the download queue size - min_request_queue = 2, + min_request_queue = 2 }; namespace { diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 503751a97..50f16ce05 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -2703,18 +2703,6 @@ retry: return port; } - // used to cache the current time - // every 100 ms. This is cheaper - // than a system call and can be - // used where more accurate time - // is not necessary - extern time_point g_current_time; - - initialize_timer::initialize_timer() - { - g_current_time = clock_type::now(); - } - int session_impl::rate_limit(peer_class_t c, int channel) const { TORRENT_ASSERT(channel >= 0 && channel <= 1); @@ -2824,8 +2812,9 @@ retry: // submit all disk jobs when we leave this function deferred_submit_jobs(); - time_point now = clock_type::now(); - aux::g_current_time = now; + aux::update_time_now(); + time_point now = aux::time_now(); + // too expensive // INVARIANT_CHECK; diff --git a/src/time.cpp b/src/time.cpp index 1a3793f2c..b518cdb83 100644 --- a/src/time.cpp +++ b/src/time.cpp @@ -46,9 +46,14 @@ namespace libtorrent { namespace aux // than a system call and can be // used where more accurate time // is not necessary - time_point g_current_time; + namespace { + time_point g_current_time = clock_type::now(); + } time_point const& time_now() { return aux::g_current_time; } + void update_time_now() { g_current_time = clock_type::now(); } + + } } diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index 4dacc5832..dade73519 100644 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -94,7 +94,8 @@ namespace libtorrent // fixes invalid UTF-8 sequences and // replaces characters that are invalid // in paths - TORRENT_EXTRA_EXPORT bool verify_encoding(std::string& target, bool fix_paths = false) + TORRENT_EXTRA_EXPORT bool verify_encoding(std::string& target + , bool fix_paths) { if (target.empty()) return true; diff --git a/src/utf8.cpp b/src/utf8.cpp index 9fb6845d5..2bd285bf3 100644 --- a/src/utf8.cpp +++ b/src/utf8.cpp @@ -50,6 +50,9 @@ namespace libtorrent , UTF8 const* src_end , std::wstring& wide) { + TORRENT_UNUSED(src_start); + TORRENT_UNUSED(src_end); + TORRENT_UNUSED(wide); return source_illegal; } }; @@ -62,13 +65,15 @@ namespace libtorrent , char const* src_end , std::wstring& wide) { - wchar_t const* dst_start = wide.c_str(); - int ret = ConvertUTF8toUTF32((UTF8 const**)src_start - , (UTF8 const*)src_end - , (UTF32**)&dst_start, (UTF32*)dst_start + wide.size() + wchar_t* dst_start = &wide[0]; + int ret = ConvertUTF8toUTF32( + reinterpret_cast(src_start) + , reinterpret_cast(src_end) + , reinterpret_cast(&dst_start) + , reinterpret_cast(dst_start + wide.size()) , lenientConversion); wide.resize(dst_start - wide.c_str()); - return (utf8_conv_result_t)ret; + return static_cast(ret); } }; @@ -80,13 +85,15 @@ namespace libtorrent , char const* src_end , std::wstring& wide) { - wchar_t const* dst_start = wide.c_str(); - int ret = ConvertUTF8toUTF16((UTF8 const**)src_start - , (UTF8 const*)src_end - , (UTF16**)&dst_start, (UTF16*)dst_start + wide.size() + wchar_t* dst_start = &wide[0]; + int ret = ConvertUTF8toUTF16( + reinterpret_cast(src_start) + , reinterpret_cast(src_end) + , reinterpret_cast(&dst_start) + , reinterpret_cast(dst_start + wide.size()) , lenientConversion); wide.resize(dst_start - wide.c_str()); - return (utf8_conv_result_t)ret; + return static_cast(ret); } }; @@ -98,6 +105,9 @@ namespace libtorrent , wchar_t const* src_end , std::string& utf8) { + TORRENT_UNUSED(src_start); + TORRENT_UNUSED(src_end); + TORRENT_UNUSED(utf8); return source_illegal; } }; @@ -110,13 +120,15 @@ namespace libtorrent , wchar_t const* src_end , std::string& utf8) { - char const* dst_start = utf8.c_str(); - int ret = ConvertUTF32toUTF8((UTF32 const**)src_start - , (UTF32 const*)src_end, (UTF8**)&dst_start - , (UTF8*)dst_start + utf8.size() + char* dst_start = &utf8[0]; + int ret = ConvertUTF32toUTF8( + reinterpret_cast(src_start) + , reinterpret_cast(src_end) + , reinterpret_cast(&dst_start) + , reinterpret_cast(dst_start + utf8.size()) , lenientConversion); utf8.resize(dst_start - &utf8[0]); - return (utf8_conv_result_t)ret; + return static_cast(ret); } }; @@ -128,13 +140,15 @@ namespace libtorrent , wchar_t const* src_end , std::string& utf8) { - char const* dst_start = utf8.c_str(); - int ret = ConvertUTF16toUTF8((UTF16 const**)src_start - , (UTF16 const*)src_end, (UTF8**)&dst_start - , (UTF8*)dst_start + utf8.size() + char* dst_start = &utf8[0]; + int ret = ConvertUTF16toUTF8( + reinterpret_cast(src_start) + , reinterpret_cast(src_end) + , reinterpret_cast(&dst_start) + , reinterpret_cast(dst_start + utf8.size()) , lenientConversion); utf8.resize(dst_start - &utf8[0]); - return (utf8_conv_result_t)ret; + return static_cast(ret); } }; } // anonymous namespace @@ -143,7 +157,6 @@ namespace libtorrent { // allocate space for worst-case wide.resize(utf8.size()); - wchar_t const* dst_start = wide.c_str(); char const* src_start = utf8.c_str(); return convert_to_wide::convert( &src_start, src_start + utf8.size(), wide); @@ -154,7 +167,6 @@ namespace libtorrent // allocate space for worst-case utf8.resize(wide.size() * 6); if (wide.empty()) return conversion_ok; - char* dst_start = &utf8[0]; wchar_t const* src_start = wide.c_str(); return convert_from_wide::convert( &src_start, src_start + wide.size(), utf8); diff --git a/test/test_torrent_info.cpp b/test/test_torrent_info.cpp index 8619d33ab..0ebb58756 100644 --- a/test/test_torrent_info.cpp +++ b/test/test_torrent_info.cpp @@ -150,13 +150,6 @@ test_failing_torrent_t test_error_torrents[] = { "invalid_file_size.torrent", errors::torrent_invalid_length }, }; -namespace libtorrent -{ - // defined in torrent_info.cpp - TORRENT_EXPORT bool verify_encoding(std::string& target, bool path = true); - TORRENT_EXTRA_EXPORT void sanitize_append_path_element(std::string& p, char const* element, int len); -} - // TODO: test remap_files // TODO: merkle torrents. specifically torrent_info::add_merkle_nodes and torrent with "root hash" // TODO: torrent with 'p' (padfile) attribute @@ -271,7 +264,7 @@ int test_torrent_parse() // verify_encoding std::string test = "\b?filename=4"; - TEST_CHECK(!verify_encoding(test)); + TEST_CHECK(!verify_encoding(test, true)); #ifdef TORRENT_WINDOWS TEST_CHECK(test == "__filename=4"); #else @@ -279,75 +272,75 @@ int test_torrent_parse() #endif test = "filename=4"; - TEST_CHECK(verify_encoding(test)); + TEST_CHECK(verify_encoding(test, true)); TEST_CHECK(test == "filename=4"); // valid 2-byte sequence test = "filename\xc2\xa1"; - TEST_CHECK(verify_encoding(test)); + TEST_CHECK(verify_encoding(test, true)); fprintf(stderr, "%s\n", test.c_str()); TEST_CHECK(test == "filename\xc2\xa1"); // truncated 2-byte sequence test = "filename\xc2"; - TEST_CHECK(!verify_encoding(test)); + TEST_CHECK(!verify_encoding(test, true)); fprintf(stderr, "%s\n", test.c_str()); TEST_CHECK(test == "filename_"); // valid 3-byte sequence test = "filename\xe2\x9f\xb9"; - TEST_CHECK(verify_encoding(test)); + TEST_CHECK(verify_encoding(test, true)); fprintf(stderr, "%s\n", test.c_str()); TEST_CHECK(test == "filename\xe2\x9f\xb9"); // truncated 3-byte sequence test = "filename\xe2\x9f"; - TEST_CHECK(!verify_encoding(test)); + TEST_CHECK(!verify_encoding(test, true)); fprintf(stderr, "%s\n", test.c_str()); TEST_CHECK(test == "filename_"); // truncated 3-byte sequence test = "filename\xe2"; - TEST_CHECK(!verify_encoding(test)); + TEST_CHECK(!verify_encoding(test, true)); fprintf(stderr, "%s\n", test.c_str()); TEST_CHECK(test == "filename_"); // valid 4-byte sequence test = "filename\xf0\x9f\x92\x88"; - TEST_CHECK(verify_encoding(test)); + TEST_CHECK(verify_encoding(test, true)); fprintf(stderr, "%s\n", test.c_str()); TEST_CHECK(test == "filename\xf0\x9f\x92\x88"); // truncated 4-byte sequence test = "filename\xf0\x9f\x92"; - TEST_CHECK(!verify_encoding(test)); + TEST_CHECK(!verify_encoding(test, true)); fprintf(stderr, "%s\n", test.c_str()); TEST_CHECK(test == "filename_"); // 5-byte utf-8 sequence (not allowed) test = "filename\xf8\x9f\x9f\x9f\x9f""foobar"; - TEST_CHECK(!verify_encoding(test)); + TEST_CHECK(!verify_encoding(test, true)); fprintf(stderr, "%s\n", test.c_str()); TEST_CHECK(test == "filename_____foobar"); // redundant (overlong) 2-byte sequence // ascii code 0x2e encoded with a leading 0 test = "filename\xc0\xae"; - TEST_CHECK(!verify_encoding(test)); + TEST_CHECK(!verify_encoding(test, true)); fprintf(stderr, "%s\n", test.c_str()); TEST_CHECK(test == "filename__"); // redundant (overlong) 3-byte sequence // ascii code 0x2e encoded with two leading 0s test = "filename\xe0\x80\xae"; - TEST_CHECK(!verify_encoding(test)); + TEST_CHECK(!verify_encoding(test, true)); fprintf(stderr, "%s\n", test.c_str()); TEST_CHECK(test == "filename___"); // redundant (overlong) 4-byte sequence // ascii code 0x2e encoded with three leading 0s test = "filename\xf0\x80\x80\xae"; - TEST_CHECK(!verify_encoding(test)); + TEST_CHECK(!verify_encoding(test, true)); fprintf(stderr, "%s\n", test.c_str()); TEST_CHECK(test == "filename____"); @@ -499,8 +492,10 @@ int test_torrent_parse() { error_code ec; fprintf(stderr, "loading %s\n", test_error_torrents[i].file); - boost::shared_ptr ti(new torrent_info(combine_path(combine_path(root_dir, "test_torrents"), test_error_torrents[i].file), ec)); - fprintf(stderr, "E: \"%s\"\nexpected: \"%s\"\n", ec.message().c_str(), test_error_torrents[i].error.message().c_str()); + boost::shared_ptr ti(new torrent_info(combine_path( + combine_path(root_dir, "test_torrents"), test_error_torrents[i].file), ec)); + fprintf(stderr, "E: \"%s\"\nexpected: \"%s\"\n", ec.message().c_str() + , test_error_torrents[i].error.message().c_str()); TEST_CHECK(ec.message() == test_error_torrents[i].error.message()); }