fix more warnings
This commit is contained in:
parent
6a87dc7d84
commit
12c9d3de26
6
Jamfile
6
Jamfile
|
@ -247,7 +247,11 @@ rule warnings ( properties * )
|
|||
result += <cflags>-Wno-documentation-unknown-command ;
|
||||
result += <cflags>-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 += <cflags>-Wno-non-virtual-dtor ;
|
||||
|
||||
# enable these warnings again, once the other ones are delt with
|
||||
result += <cflags>-Wno-weak-vtables ;
|
||||
result += <cflags>-Wno-sign-compare ;
|
||||
result += <cflags>-Wno-sign-conversion ;
|
||||
|
|
|
@ -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<bencode_map_entry*, int> 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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -94,7 +94,7 @@ namespace libtorrent
|
|||
enum
|
||||
{
|
||||
// the limits of the download queue size
|
||||
min_request_queue = 2,
|
||||
min_request_queue = 2
|
||||
};
|
||||
|
||||
namespace {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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(); }
|
||||
|
||||
|
||||
} }
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
56
src/utf8.cpp
56
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<UTF8 const**>(src_start)
|
||||
, reinterpret_cast<UTF8 const*>(src_end)
|
||||
, reinterpret_cast<UTF32**>(&dst_start)
|
||||
, reinterpret_cast<UTF32*>(dst_start + wide.size())
|
||||
, lenientConversion);
|
||||
wide.resize(dst_start - wide.c_str());
|
||||
return (utf8_conv_result_t)ret;
|
||||
return static_cast<utf8_conv_result_t>(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<UTF8 const**>(src_start)
|
||||
, reinterpret_cast<UTF8 const*>(src_end)
|
||||
, reinterpret_cast<UTF16**>(&dst_start)
|
||||
, reinterpret_cast<UTF16*>(dst_start + wide.size())
|
||||
, lenientConversion);
|
||||
wide.resize(dst_start - wide.c_str());
|
||||
return (utf8_conv_result_t)ret;
|
||||
return static_cast<utf8_conv_result_t>(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<UTF32 const**>(src_start)
|
||||
, reinterpret_cast<UTF32 const*>(src_end)
|
||||
, reinterpret_cast<UTF8**>(&dst_start)
|
||||
, reinterpret_cast<UTF8*>(dst_start + utf8.size())
|
||||
, lenientConversion);
|
||||
utf8.resize(dst_start - &utf8[0]);
|
||||
return (utf8_conv_result_t)ret;
|
||||
return static_cast<utf8_conv_result_t>(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<UTF16 const**>(src_start)
|
||||
, reinterpret_cast<UTF16 const*>(src_end)
|
||||
, reinterpret_cast<UTF8**>(&dst_start)
|
||||
, reinterpret_cast<UTF8*>(dst_start + utf8.size())
|
||||
, lenientConversion);
|
||||
utf8.resize(dst_start - &utf8[0]);
|
||||
return (utf8_conv_result_t)ret;
|
||||
return static_cast<utf8_conv_result_t>(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<sizeof(wchar_t)>::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<sizeof(wchar_t)>::convert(
|
||||
&src_start, src_start + wide.size(), utf8);
|
||||
|
|
|
@ -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<torrent_info> 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<torrent_info> 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());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue