From 821e34c79529b27f55982f203543e99c5daca709 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 25 Apr 2015 04:22:51 +0000 Subject: [PATCH] fix examples build. fix print formatting bugs. fix some gcc warnings --- Jamfile | 3 +++ examples/session_view.hpp | 3 ++- examples/stats_counters.cpp | 2 +- include/libtorrent/file_storage.hpp | 3 ++- include/libtorrent/stat.hpp | 13 ++++++------- include/libtorrent/torrent_info.hpp | 14 +++++++------- src/block_cache.cpp | 2 +- src/bt_peer_connection.cpp | 6 +++--- src/file_storage.cpp | 7 ++++++- src/http_seed_connection.cpp | 3 ++- src/peer_connection.cpp | 16 +++++++++------- src/receive_buffer.cpp | 2 +- src/session_impl.cpp | 8 ++++---- src/torrent.cpp | 2 +- src/ut_pex.cpp | 5 +++-- src/web_peer_connection.cpp | 10 ++++++---- test/test_merkle.cpp | 1 + 17 files changed, 58 insertions(+), 42 deletions(-) diff --git a/Jamfile b/Jamfile index 9585bc83e..d33fc761a 100755 --- a/Jamfile +++ b/Jamfile @@ -251,6 +251,9 @@ rule warnings ( properties * ) { result += -Wall ; result += -Wextra ; + +# enable these warnings again, once the other ones are dealt with + result += -Wno-sign-compare ; } if msvc in $(properties) diff --git a/examples/session_view.hpp b/examples/session_view.hpp index 590787dfd..12fa29860 100644 --- a/examples/session_view.hpp +++ b/examples/session_view.hpp @@ -1,7 +1,8 @@ #ifndef SESSION_VIEW_HPP_ #define SESSION_VIEW_HPP_ -#include "libtorrent/session.hpp" +#include "libtorrent/session_stats.hpp" +#include namespace lt = libtorrent; diff --git a/examples/stats_counters.cpp b/examples/stats_counters.cpp index d42941ccf..b39b41e05 100644 --- a/examples/stats_counters.cpp +++ b/examples/stats_counters.cpp @@ -31,7 +31,7 @@ POSSIBILITY OF SUCH DAMAGE. */ #include -#include +#include "libtorrent/session_stats.hpp" using namespace libtorrent; diff --git a/include/libtorrent/file_storage.hpp b/include/libtorrent/file_storage.hpp index f54e147fe..4b8d09053 100644 --- a/include/libtorrent/file_storage.hpp +++ b/include/libtorrent/file_storage.hpp @@ -198,7 +198,7 @@ namespace libtorrent // represents a window of a file in a torrent. // // The ``file_index`` refers to the index of the file (in the torrent_info). - // To get the path and filename, use ``file_at()`` and give the ``file_index`` + // To get the path and filename, use ``file_path()`` and give the ``file_index`` // as argument. The ``offset`` is the byte offset in the file where the range // starts, and ``size`` is the number of bytes this range is. The size + offset // will never be greater than the file size. @@ -378,6 +378,7 @@ namespace libtorrent reverse_iterator rbegin_deprecated() const { return m_files.rbegin(); } reverse_iterator rend_deprecated() const { return m_files.rend(); } iterator file_at_offset_deprecated(boost::int64_t offset) const; + file_entry at_deprecated(int index) const; #endif // TORRENT_NO_DEPRECATE // returns the number of files in the file_storage diff --git a/include/libtorrent/stat.hpp b/include/libtorrent/stat.hpp index 9170ed1f8..a68674530 100644 --- a/include/libtorrent/stat.hpp +++ b/include/libtorrent/stat.hpp @@ -37,6 +37,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include #include "libtorrent/invariant_check.hpp" @@ -57,20 +58,20 @@ namespace libtorrent void operator+=(stat_channel const& s) { - TORRENT_ASSERT(m_total_counter >= 0); + TORRENT_ASSERT(m_counter < (std::numeric_limits::max)() - s.m_counter); m_counter += s.m_counter; + TORRENT_ASSERT(m_total_counter < (std::numeric_limits::max)() - s.m_counter); m_total_counter += s.m_counter; - TORRENT_ASSERT(m_counter >= m_counter - s.m_counter); } void add(int count) { TORRENT_ASSERT(count >= 0); + TORRENT_ASSERT(m_counter < (std::numeric_limits::max)() - count); m_counter += count; - TORRENT_ASSERT(m_counter >= m_counter - count); + TORRENT_ASSERT(m_total_counter < (std::numeric_limits::max)() - count); m_total_counter += count; - TORRENT_ASSERT(m_total_counter >= m_total_counter - count); } // should be called once every second @@ -82,10 +83,8 @@ namespace libtorrent void offset(boost::int64_t c) { - TORRENT_ASSERT(c >= 0); - TORRENT_ASSERT(m_total_counter >= 0); + TORRENT_ASSERT(m_total_counter < (std::numeric_limits::max)() - c); m_total_counter += c; - TORRENT_ASSERT(m_total_counter >= 0); } int counter() const { return m_counter; } diff --git a/include/libtorrent/torrent_info.hpp b/include/libtorrent/torrent_info.hpp index 0ce5d87c0..78034b7fe 100644 --- a/include/libtorrent/torrent_info.hpp +++ b/include/libtorrent/torrent_info.hpp @@ -485,23 +485,23 @@ namespace libtorrent // (``file_entry``) using the ``file_storage::at`` function, which takes // an index and an iterator. TORRENT_DEPRECATED - file_iterator begin_files() const TORRENT_DEPRECATED { return m_files.begin_deprecated(); } + file_iterator begin_files() const { return m_files.begin_deprecated(); } TORRENT_DEPRECATED - file_iterator end_files() const TORRENT_DEPRECATED { return m_files.end_deprecated(); } - reverse_file_iterator rbegin_files() const TORRENT_DEPRECATED { return m_files.rbegin_deprecated(); } + file_iterator end_files() const { return m_files.end_deprecated(); } + reverse_file_iterator rbegin_files() const { return m_files.rbegin_deprecated(); } TORRENT_DEPRECATED - reverse_file_iterator rend_files() const TORRENT_DEPRECATED { return m_files.rend_deprecated(); } + reverse_file_iterator rend_files() const { return m_files.rend_deprecated(); } TORRENT_DEPRECATED - file_iterator file_at_offset(boost::int64_t offset) const TORRENT_DEPRECATED + file_iterator file_at_offset(boost::int64_t offset) const { return m_files.file_at_offset_deprecated(offset); } TORRENT_DEPRECATED - file_entry file_at(int index) const TORRENT_DEPRECATED{ return m_files.at(index); } + file_entry file_at(int index) const { return m_files.at_deprecated(index); } #endif // TORRENT_NO_DEPRECATE // If you need index-access to files you can use the ``num_files()`` and - // ``file_at()`` to access files using indices. + // ``file_path()`` et.al. to access files using indices. int num_files() const { return m_files.num_files(); } // This function will map a piece index, a byte offset within that piece diff --git a/src/block_cache.cpp b/src/block_cache.cpp index 1d22cfa64..49ac021eb 100644 --- a/src/block_cache.cpp +++ b/src/block_cache.cpp @@ -262,7 +262,7 @@ const char* const job_action_name[] = "hashing_done: %d\nmarked_for_deletion: %d\nneed_readback: %d\n" "hash_passed: %d\nread_jobs: %d\njobs: %d\n" "piece_log:\n" - , int(pe->piece), pe->refcount, pe->piece_refcount, pe->num_blocks + , int(pe->piece), pe->refcount, pe->piece_refcount, int(pe->num_blocks) , int(pe->hashing), pe->hash, pe->hash ? pe->hash->offset : -1 , int(pe->cache_state), pe->cache_state >= 0 && pe->cache_state < cached_piece_entry::num_lrus ? cache_state[pe->cache_state] : "" diff --git a/src/bt_peer_connection.cpp b/src/bt_peer_connection.cpp index 0a8224f6d..17138c477 100644 --- a/src/bt_peer_connection.cpp +++ b/src/bt_peer_connection.cpp @@ -2550,7 +2550,7 @@ namespace libtorrent int consumed = m_enc_handler.decrypt(m_recv_buffer, bytes_transferred); #ifndef TORRENT_DISABLE_LOGGING if (consumed + bytes_transferred > 0) - peer_log("<== decrypted block [ s = %d ]", consumed + bytes_transferred); + peer_log("<== decrypted block [ s = %d ]", int(consumed + bytes_transferred)); #endif if (bytes_transferred == SIZE_MAX) { @@ -2721,7 +2721,7 @@ namespace libtorrent std::size_t bytes_processed = syncoffset + 20; #ifndef TORRENT_DISABLE_LOGGING peer_log("*** sync point (hash) found at offset %d" - , m_sync_bytes_read + bytes_processed - 20); + , int(m_sync_bytes_read + bytes_processed - 20)); #endif m_state = read_pe_skey_vc; // skey,vc - 28 bytes @@ -2857,7 +2857,7 @@ namespace libtorrent std::size_t bytes_processed = syncoffset + 8; #ifndef TORRENT_DISABLE_LOGGING peer_log("*** sync point (verification constant) found at offset %d" - , m_sync_bytes_read + bytes_processed - 8); + , int(m_sync_bytes_read + bytes_processed - 8)); #endif int transferred_used = bytes_processed - recv_buffer.left() + bytes_transferred; TORRENT_ASSERT(transferred_used <= int(bytes_transferred)); diff --git a/src/file_storage.cpp b/src/file_storage.cpp index 220ea9f71..c420b209d 100644 --- a/src/file_storage.cpp +++ b/src/file_storage.cpp @@ -460,6 +460,11 @@ namespace libtorrent #ifndef TORRENT_NO_DEPRECATE file_entry file_storage::at(int index) const + { + return at_deprecated(index); + } + + file_entry file_storage::at_deprecated(int index) const { TORRENT_ASSERT_PRECOND(index >= 0 && index < int(m_files.size())); file_entry ret; @@ -890,7 +895,7 @@ namespace libtorrent } file_entry file_storage::at(file_storage::iterator i) const - { return at(i - m_files.begin()); } + { return at_deprecated(i - m_files.begin()); } #endif // TORRENT_NO_DEPRECATE void file_storage::reorder_file(int index, int dst) diff --git a/src/http_seed_connection.cpp b/src/http_seed_connection.cpp index bb2a657da..8d65291f4 100644 --- a/src/http_seed_connection.cpp +++ b/src/http_seed_connection.cpp @@ -377,7 +377,8 @@ namespace libtorrent else { #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** parsed chunk: %d header_size: %d", chunk_size, header_size); + peer_log("*** parsed chunk: %" PRId64 " header_size: %d" + , chunk_size, header_size); #endif TORRENT_ASSERT(bytes_transferred >= size_t(header_size - m_partial_chunk_header)); bytes_transferred -= header_size - m_partial_chunk_header; diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 78de6562d..87334b118 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -1829,7 +1829,8 @@ namespace libtorrent if (index >= int(m_have_piece.size()) || index < 0) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** ERROR: [ have-metadata have_piece.size: %d ]", index, int(m_have_piece.size())); + peer_log("*** ERROR: [ have-metadata have_piece: %d size: %d ]" + , index, int(m_have_piece.size())); #endif disconnect(errors::invalid_have, op_bittorrent, 2); return; @@ -4719,7 +4720,7 @@ namespace libtorrent { #ifndef TORRENT_DISABLE_LOGGING peer_log("*** MUTUAL NO INTEREST [ t1: %d t2: %d ]" - , total_seconds(d1), total_seconds(d2)); + , int(total_seconds(d1)), int(total_seconds(d2))); #endif disconnect(errors::timed_out_no_interest, op_bittorrent); return; @@ -4771,7 +4772,7 @@ namespace libtorrent // re-request the blocks. #ifndef TORRENT_DISABLE_LOGGING peer_log("*** PIECE_REQUEST TIMED OUT [ %d time: %d to: %d ]" - , (int)m_download_queue.size(), total_seconds(now - m_last_piece) + , int(m_download_queue.size()), int(total_seconds(now - m_last_piece)) , piece_timeout); #endif @@ -5665,7 +5666,8 @@ namespace libtorrent if (ret == 0 && !ec) ec = asio::error::eof; #ifndef TORRENT_DISABLE_LOGGING - peer_log("<<< SYNC_READ [ max: %d ret: %d e: %s ]", max_receive, ret, ec ? ec.message().c_str() : ""); + peer_log("<<< SYNC_READ [ max: %d ret: %d e: %s ]" + , max_receive, int(ret), ec ? ec.message().c_str() : ""); #endif return ret; } @@ -5783,7 +5785,7 @@ namespace libtorrent } #ifndef TORRENT_DISABLE_LOGGING - peer_log("<<< READ_AVAILABLE [ bytes: %d ]", buffer_size); + peer_log("<<< READ_AVAILABLE [ bytes: %d ]", int(buffer_size)); #endif // at this point the ioctl told us the socket doesn't have any @@ -5891,7 +5893,7 @@ namespace libtorrent TORRENT_ASSERT(is_single_thread()); #ifndef TORRENT_DISABLE_LOGGING peer_log("<<< ON_RECEIVE_DATA [ bytes: %d error: %s ]" - , bytes_transferred, error.message().c_str()); + , int(bytes_transferred), error.message().c_str()); #endif // submit all disk jobs later @@ -5929,7 +5931,7 @@ namespace libtorrent #ifndef TORRENT_DISABLE_LOGGING peer_log("<<< ON_RECEIVE_DATA [ bytes: %d error: %s ]" - , bytes_transferred, error.message().c_str()); + , int(bytes_transferred), error.message().c_str()); #endif if (m_extension_outstanding_bytes > 0) diff --git a/src/receive_buffer.cpp b/src/receive_buffer.cpp index fd1df162b..8b7ecd987 100644 --- a/src/receive_buffer.cpp +++ b/src/receive_buffer.cpp @@ -137,7 +137,7 @@ void receive_buffer::cut(int size, int packet_size, int offset) TORRENT_ASSERT(int(m_recv_buffer.size()) >= m_recv_pos); TORRENT_ASSERT(m_recv_pos >= size + offset); TORRENT_ASSERT(offset >= 0); - TORRENT_ASSERT(m_recv_buffer.size() >= m_recv_end); + TORRENT_ASSERT(int(m_recv_buffer.size()) >= m_recv_end); TORRENT_ASSERT(m_recv_start <= m_recv_end); TORRENT_ASSERT(size >= 0); diff --git a/src/session_impl.cpp b/src/session_impl.cpp index be1b7df1e..0bde836af 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -532,7 +532,7 @@ namespace aux { if (getrlimit(RLIMIT_NOFILE, &rl) == 0) { #ifndef TORRENT_DISABLE_LOGGING - session_log(" max number of open files: %d", rl.rlim_cur); + session_log(" max number of open files: %d", int(rl.rlim_cur)); #endif // deduct some margin for epoll/kqueue, log files, // futexes, shared objects etc. @@ -1035,7 +1035,7 @@ namespace aux { #endif #ifndef TORRENT_DISABLE_LOGGING - session_log(" aborting all torrents (%d)", m_torrents.size()); + session_log(" aborting all torrents (%d)", int(m_torrents.size())); #endif // abort all torrents for (torrent_map::iterator i = m_torrents.begin() @@ -1051,7 +1051,7 @@ namespace aux { m_tracker_manager.abort_all_requests(); #ifndef TORRENT_DISABLE_LOGGING - session_log(" aborting all connections (%d)", m_connections.size()); + session_log(" aborting all connections (%d)", int(m_connections.size())); #endif // abort all connections while (!m_connections.empty()) @@ -2389,7 +2389,7 @@ retry: { #ifndef TORRENT_DISABLE_LOGGING session_log("%s <== INCOMING CONNECTION FAILED, could " - "not retrieve remote endpoint " + "not retrieve remote endpoint %s: %s" , print_endpoint(endp).c_str(), ec.message().c_str()); #endif return; diff --git a/src/torrent.cpp b/src/torrent.cpp index 335c16ddc..4e3c7e41e 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -3488,7 +3488,7 @@ namespace libtorrent , print_endpoint(p->ip()).c_str() , p->rank(external, m_ses.listen_port()) , print_address(external.external_address(p->address())).c_str() - , m_ses.session_time() - p->last_connected); + , int(m_ses.session_time() - p->last_connected)); #endif if (!connect_to_peer(p)) diff --git a/src/ut_pex.cpp b/src/ut_pex.cpp index 163e93f2b..e03d2d90a 100644 --- a/src/ut_pex.cpp +++ b/src/ut_pex.cpp @@ -434,7 +434,7 @@ namespace libtorrent { namespace { #ifndef TORRENT_DISABLE_LOGGING m_pc.peer_log("*** PEX [ waiting: %d seconds to next msg ]" - , total_seconds(seconds(60) - (now - m_last_msg))); + , int(total_seconds(seconds(60) - (now - m_last_msg)))); #endif return; } @@ -451,7 +451,8 @@ namespace libtorrent { namespace if (now - milliseconds(delay) < global_last) { #ifndef TORRENT_DISABLE_LOGGING - m_pc.peer_log("*** PEX [ global-wait: %d ]", total_seconds(milliseconds(delay) - (now - global_last))); + m_pc.peer_log("*** PEX [ global-wait: %d ]" + , int(total_seconds(milliseconds(delay) - (now - global_last)))); #endif return; } diff --git a/src/web_peer_connection.cpp b/src/web_peer_connection.cpp index f1e3d80d4..abde31da0 100644 --- a/src/web_peer_connection.cpp +++ b/src/web_peer_connection.cpp @@ -290,7 +290,7 @@ void web_peer_connection::write_request(peer_request const& r) TORRENT_ASSERT(front.length > int(m_piece.size())); #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** RESTART-DATA: [ data: %d req: (%d, %d) ]" + peer_log("*** RESTART-DATA: [ data: %d req: (%d, %d) size: %d ]" , int(m_piece.size()), int(front.piece), int(front.start) , int (front.start + front.length - 1)); #endif @@ -430,7 +430,7 @@ bool web_peer_connection::maybe_harvest_block() peer_request const& front_request = m_requests.front(); if (int(m_piece.size()) < front_request.length) return false; - TORRENT_ASSERT(int(m_piece.size() == front_request.length)); + TORRENT_ASSERT(int(m_piece.size()) == front_request.length); // each call to incoming_piece() may result in us becoming // a seed. If we become a seed, all seeds we're connected to @@ -823,7 +823,8 @@ void web_peer_connection::on_receive(error_code const& error else { #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** parsed chunk: %d header_size: %d", chunk_size, header_size); + peer_log("*** parsed chunk: %" PRId64 " header_size: %d" + , chunk_size, header_size); #endif TORRENT_ASSERT(int(bytes_transferred) >= header_size - m_partial_chunk_header); bytes_transferred -= header_size - m_partial_chunk_header; @@ -921,7 +922,8 @@ void web_peer_connection::on_receive(error_code const& error std::vector sl = info.orig_files().map_block( front_request.piece, front_request.start, front_request.start + front_request.length); - peer_log("INVALID HTTP RESPONSE [ in=(%d, %d-%d) expected=(%d, %d-%d) piece: %d ]" + peer_log("INVALID HTTP RESPONSE [ in=(%d, %" PRId64 "-%" PRId64 ") " + "expected=(%d, %" PRId64 "-%" PRId64 ") piece: %d ]" , file_index, range_start, range_end, sl[0].file_index , sl[0].offset, sl[0].offset + sl[0].size, front_request.piece); #endif diff --git a/test/test_merkle.cpp b/test/test_merkle.cpp index b179840dc..e6fa0aef4 100644 --- a/test/test_merkle.cpp +++ b/test/test_merkle.cpp @@ -104,5 +104,6 @@ int test_main() TEST_EQUAL(merkle_num_nodes(8), 15); TEST_EQUAL(merkle_num_nodes(16), 31); + return 0; }