diff --git a/include/libtorrent/bencode.hpp b/include/libtorrent/bencode.hpp index 9eba2fbb4..a27aebdcf 100644 --- a/include/libtorrent/bencode.hpp +++ b/include/libtorrent/bencode.hpp @@ -122,8 +122,8 @@ namespace libtorrent ++ret; } return ret; - } - + } + template void write_char(OutIt& out, char c) { diff --git a/src/disk_buffer_pool.cpp b/src/disk_buffer_pool.cpp index 06e8cb1da..7462d9349 100644 --- a/src/disk_buffer_pool.cpp +++ b/src/disk_buffer_pool.cpp @@ -188,7 +188,8 @@ namespace libtorrent { l.unlock(); m_ios.post(boost::bind(&watermark_callback - , (std::vector >*)NULL, slice)); + , static_cast >*>(NULL) + , slice)); return; } @@ -199,7 +200,8 @@ namespace libtorrent { l.unlock(); m_ios.post(boost::bind(&watermark_callback - , (std::vector >*)NULL, handlers)); + , static_cast >*>(NULL) + , handlers)); return; } @@ -307,7 +309,7 @@ namespace libtorrent // we need to roll back and free all the buffers // we've already allocated for (int j = 0; j < i; ++j) - free_buffer_impl((char*)iov[j].iov_base, l); + free_buffer_impl(static_cast(iov[j].iov_base), l); return -1; } } @@ -319,7 +321,7 @@ namespace libtorrent // TODO: perhaps we should sort the buffers here? mutex::scoped_lock l(m_pool_mutex); for (int i = 0; i < iov_len; ++i) - free_buffer_impl((char*)iov[i].iov_base, l); + free_buffer_impl(static_cast(iov[i].iov_base), l); check_buffer_level(l); } @@ -575,8 +577,8 @@ namespace libtorrent #define MAP_NOCACHE 0 #endif ftruncate(m_cache_fd, boost::uint64_t(m_max_use) * 0x4000); - m_cache_pool = (char*)mmap(0, boost::uint64_t(m_max_use) * 0x4000, PROT_READ | PROT_WRITE - , MAP_SHARED | MAP_NOCACHE, m_cache_fd, 0); + m_cache_pool = static_cast(mmap(0, boost::uint64_t(m_max_use) * 0x4000, PROT_READ | PROT_WRITE + , MAP_SHARED | MAP_NOCACHE, m_cache_fd, 0)); if (intptr_t(m_cache_pool) == -1) { ec.assign(errno, boost::system::generic_category()); diff --git a/src/disk_io_job.cpp b/src/disk_io_job.cpp index 3ee441e5a..621f9d46e 100644 --- a/src/disk_io_job.cpp +++ b/src/disk_io_job.cpp @@ -63,7 +63,7 @@ namespace libtorrent if (action == rename_file || action == move_storage) free(buffer.string); else if (action == save_resume_data) - delete (entry*)buffer.resume_data; + delete static_cast(buffer.resume_data); } bool disk_io_job::completed(cached_piece_entry const* pe, int block_size) diff --git a/src/entry.cpp b/src/entry.cpp index 2b1aac955..0a6bf01b5 100644 --- a/src/entry.cpp +++ b/src/entry.cpp @@ -586,7 +586,7 @@ namespace libtorrent { // currently, only swapping entries of the same type or where one // of the entries is uninitialized is supported. - TORRENT_ASSERT(false && "not implemented"); + TORRENT_ASSERT(false); } } @@ -605,7 +605,7 @@ namespace libtorrent { case int_t: out += libtorrent::to_string(integer()).elems; - out += "\n"; + out += "\n"; break; case string_t: { diff --git a/src/file.cpp b/src/file.cpp index 513f86569..ab3a1b0d1 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -1620,7 +1620,7 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER { int buf_size = bufs_size(bufs, num_bufs); // this is page aligned since it's used in APIs which // are likely to require that (depending on OS) - char* buf = (char*)page_aligned_allocator::malloc(buf_size); + char* buf = static_cast(page_aligned_allocator::malloc(buf_size)); if (!buf) return false; tmp->iov_base = buf; tmp->iov_len = buf_size; @@ -1642,7 +1642,7 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER { // operation int buf_size = 0; for (int i = 0; i < num_bufs; ++i) buf_size += bufs[i].iov_len; - char* buf = (char*)page_aligned_allocator::malloc(buf_size); + char* buf = static_cast(page_aligned_allocator::malloc(buf_size)); if (!buf) return false; gather_copy(bufs, num_bufs, buf); tmp->iov_base = buf; @@ -1786,7 +1786,8 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER { #endif if (flags & file::coalesce_buffers) - coalesce_read_buffers_end(bufs, num_bufs, (char*)tmp.iov_base, !ec); + coalesce_read_buffers_end(bufs, num_bufs + , static_cast(tmp.iov_base), !ec); #endif return ret; diff --git a/src/file_storage.cpp b/src/file_storage.cpp index e2e7eba5d..40186a07e 100644 --- a/src/file_storage.cpp +++ b/src/file_storage.cpp @@ -280,7 +280,7 @@ namespace libtorrent if (string_len >= name_is_owned) string_len = name_is_owned - 1; // free the current string, before assigning the new one - if (name_len == name_is_owned) free((void*)name); + if (name_len == name_is_owned) free(const_cast(name)); if (n == NULL) { TORRENT_ASSERT(borrow_string == false); @@ -429,7 +429,7 @@ namespace libtorrent // find the file iterator and file offset internal_file_entry target; - target.offset = piece * (boost::int64_t)m_piece_length + offset; + target.offset = piece * boost::int64_t(m_piece_length) + offset; TORRENT_ASSERT_PRECOND(boost::int64_t(target.offset + size) <= m_total_size); TORRENT_ASSERT(!compare_file_offset(target, m_files.front())); @@ -458,7 +458,7 @@ namespace libtorrent file_offset += f.size; ret.push_back(f); } - + TORRENT_ASSERT(size >= 0); } return ret; diff --git a/src/http_connection.cpp b/src/http_connection.cpp index 0e02ab244..c406569cf 100644 --- a/src/http_connection.cpp +++ b/src/http_connection.cpp @@ -138,7 +138,7 @@ void http_connection::get(std::string const& url, time_duration timeout, int pri if (ec) { m_timer.get_io_service().post(boost::bind(&http_connection::callback - , me, ec, (char*)0, 0)); + , me, ec, static_cast(NULL), 0)); return; } @@ -150,7 +150,7 @@ void http_connection::get(std::string const& url, time_duration timeout, int pri { error_code ec(errors::unsupported_url_protocol); m_timer.get_io_service().post(boost::bind(&http_connection::callback - , me, ec, (char*)0, 0)); + , me, ec, static_cast(NULL), 0)); return; } @@ -158,7 +158,7 @@ void http_connection::get(std::string const& url, time_duration timeout, int pri bool ssl = false; if (protocol == "https") ssl = true; - + char request[4096]; char* end = request + sizeof(request); char* ptr = request; @@ -199,7 +199,7 @@ void http_connection::get(std::string const& url, time_duration timeout, int pri if (!m_user_agent.empty()) APPEND_FMT1("User-Agent: %s\r\n", m_user_agent.c_str()); - + if (m_bottled) APPEND_FMT("Accept-Encoding: gzip\r\n"); @@ -258,7 +258,7 @@ void http_connection::start(std::string const& hostname, int port if (ec) { m_timer.get_io_service().post(boost::bind(&http_connection::callback - , me, ec, (char*)0, 0)); + , me, ec, static_cast(NULL), 0)); return; } @@ -298,7 +298,7 @@ void http_connection::start(std::string const& hostname, int port if (is_i2p && i2p_conn->proxy().type != settings_pack::i2p_proxy) { m_timer.get_io_service().post(boost::bind(&http_connection::callback - , me, error_code(errors::no_i2p_router, get_libtorrent_category()), (char*)0, 0)); + , me, error_code(errors::no_i2p_router, get_libtorrent_category()), static_cast(NULL), 0)); return; } #endif @@ -354,7 +354,7 @@ void http_connection::start(std::string const& hostname, int port if (ec) { m_timer.get_io_service().post(boost::bind(&http_connection::callback - , me, ec, (char*)0, 0)); + , me, ec, static_cast(NULL), 0)); return; } } @@ -363,7 +363,7 @@ void http_connection::start(std::string const& hostname, int port if (ec) { m_timer.get_io_service().post(boost::bind(&http_connection::callback - , me, ec, (char*)0, 0)); + , me, ec, static_cast(NULL), 0)); return; } diff --git a/src/lazy_bdecode.cpp b/src/lazy_bdecode.cpp index 3acbcc93d..295d3164f 100644 --- a/src/lazy_bdecode.cpp +++ b/src/lazy_bdecode.cpp @@ -536,7 +536,7 @@ namespace libtorrent line_len += 4; break; } - + if (line_len > limit) return -1; return line_len; } @@ -552,7 +552,7 @@ namespace libtorrent else { char tmp[5]; - snprintf(tmp, sizeof(tmp), "\\x%02x", (unsigned char)str[i]); + snprintf(tmp, sizeof(tmp), "\\x%02x", boost::uint8_t(str[i])); ret += tmp; } } diff --git a/src/string_util.cpp b/src/string_util.cpp index 96ec1239a..d3249656a 100644 --- a/src/string_util.cpp +++ b/src/string_util.cpp @@ -148,7 +148,7 @@ namespace libtorrent char* allocate_string_copy(char const* str) { if (str == 0) return 0; - char* tmp = (char*)std::malloc(std::strlen(str) + 1); + char* tmp = static_cast(std::malloc(std::strlen(str) + 1)); if (tmp == 0) return 0; std::strcpy(tmp, str); return tmp; @@ -160,7 +160,7 @@ namespace libtorrent int offset = uintptr_t(p) & 0x7; // if we're already aligned, don't do anything if (offset == 0) return p; - + // offset is how far passed the last aligned address // we are. We need to go forward to the next aligned // one. Since aligned addresses are 8 bytes apart, add diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index 8cb1a45be..32f69205b 100644 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -1406,13 +1406,13 @@ namespace libtorrent hasher hs; if (sibling < n) { - hs.update((char const*)&sibling_hash->second[0], 20); - hs.update((char const*)&h[0], 20); + hs.update(sibling_hash->second.data(), 20); + hs.update(h.data(), 20); } else { - hs.update((char const*)&h[0], 20); - hs.update((char const*)&sibling_hash->second[0], 20); + hs.update(h.data(), 20); + hs.update(sibling_hash->second.data(), 20); } h = hs.final(); n = parent; diff --git a/test/main.cpp b/test/main.cpp index f9ead9365..bb5122178 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -264,8 +264,8 @@ EXPORT int main(int argc, char const* argv[]) t.output = tmpfile(); int ret1 = dup2(fileno(t.output), fileno(stdout)); - int ret2 = dup2(fileno(t.output), fileno(stderr)); - if (ret1 < 0 /*|| ret2 < 0*/) + dup2(fileno(t.output), fileno(stderr)); + if (ret1 < 0 ) { fprintf(stderr, "failed to redirect output: (%d) %s\n" , errno, strerror(errno)); diff --git a/test/test.hpp b/test/test.hpp index 77e48cd79..ee29017eb 100644 --- a/test/test.hpp +++ b/test/test.hpp @@ -44,6 +44,21 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/config.hpp" +// tests are expected to even test deprecated functionality. There is no point +// in warning about deprecated use in any of the tests. + +#if defined __clang__ +#pragma clang diagnostic ignored "-Wdeprecated" +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + +#elif defined __GNUC__ +#pragma GCC diagnostic ignored "-Wdeprecated" +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + +#elif defined _MSC_VER +#pragma warning(disable : 4996) +#endif + #if defined TORRENT_BUILDING_TEST_SHARED #define EXPORT BOOST_SYMBOL_EXPORT #elif defined TORRENT_LINK_TEST_SHARED diff --git a/test/test_bencoding.cpp b/test/test_bencoding.cpp index 1905b7859..8d687cb66 100644 --- a/test/test_bencoding.cpp +++ b/test/test_bencoding.cpp @@ -578,6 +578,7 @@ TORRENT_TEST(bencoding) bdecode_errors::error_code_enum ec; char const* e = parse_int(b, b + sizeof(b)-1, ':', val, ec); TEST_CHECK(ec == bdecode_errors::overflow); + TEST_EQUAL(e, b + 18); } { @@ -586,6 +587,7 @@ TORRENT_TEST(bencoding) bdecode_errors::error_code_enum ec; char const* e = parse_int(b, b + sizeof(b)-1, ':', val, ec); TEST_CHECK(ec == bdecode_errors::expected_colon); + TEST_EQUAL(e, b + 3); } { diff --git a/test/test_dos_blocker.cpp b/test/test_dos_blocker.cpp index def0340d4..3d0fdb267 100644 --- a/test/test_dos_blocker.cpp +++ b/test/test_dos_blocker.cpp @@ -59,6 +59,7 @@ struct log_t : libtorrent::dht::dht_logger libtorrent::bdecode_node print; libtorrent::error_code ec; int ret = bdecode(pkt, pkt + len, print, ec, NULL, 100, 100); + TEST_EQUAL(ret, 0); std::string msg = print_entry(print, true); printf("%s", msg.c_str()); diff --git a/test/test_ip_filter.cpp b/test/test_ip_filter.cpp index 5416c9b4b..06d200483 100644 --- a/test/test_ip_filter.cpp +++ b/test/test_ip_filter.cpp @@ -80,7 +80,6 @@ void test_rules_invariant(std::vector > const& r, ip_filter const& f TEST_CHECK(r.back().last == IP("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")); } - iterator i = r.begin(); for (iterator i(r.begin()), j(boost::next(r.begin())) , end(r.end()); j != end; ++j, ++i) {