From 0b063de9fff3a009f0e961466fdd2a3fa8d6efd5 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 21 Apr 2015 04:30:34 +0000 Subject: [PATCH] fix more warnings --- include/libtorrent/aux_/session_impl.hpp | 18 ++++++++-- include/libtorrent/aux_/session_interface.hpp | 12 +++++-- include/libtorrent/extensions/ut_pex.hpp | 8 ++++- include/libtorrent/file_storage.hpp | 2 +- .../libtorrent/http_tracker_connection.hpp | 4 +++ include/libtorrent/lsd.hpp | 6 +++- include/libtorrent/peer_connection.hpp | 6 +++- include/libtorrent/peer_info.hpp | 2 -- include/libtorrent/peer_list.hpp | 1 + include/libtorrent/request_blocks.hpp | 6 ++++ include/libtorrent/session.hpp | 1 + include/libtorrent/torrent.hpp | 6 +++- include/libtorrent/tracker_manager.hpp | 6 +++- src/disk_buffer_pool.cpp | 11 +++--- src/file_storage.cpp | 6 ++-- src/gzip.cpp | 8 +++-- src/lsd.cpp | 36 ++++++++++++------- src/peer_connection.cpp | 5 +++ src/platform_util.cpp | 6 ++++ src/puff.cpp | 7 ++++ src/request_blocks.cpp | 5 +-- src/session_impl.cpp | 10 ++++++ src/session_stats.cpp | 2 ++ src/torrent.cpp | 13 +++++-- src/ut_pex.cpp | 2 ++ 25 files changed, 143 insertions(+), 46 deletions(-) diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index 5f1c9a76a..193d494de 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -1128,8 +1128,16 @@ namespace libtorrent boost::uint16_t m_tick_residual; #ifndef TORRENT_DISABLE_LOGGING - virtual void session_log(char const* fmt, ...) const; - virtual void session_vlog(char const* fmt, va_list& va) const; + virtual void session_log(char const* fmt, ...) const +#if defined __GNUC__ || defined __clang__ + __attribute__((format(printf, 2, 3))) +#endif + ; + virtual void session_vlog(char const* fmt, va_list& va) const +#if defined __GNUC__ || defined __clang__ + __attribute__((format(printf, 2, 0))) +#endif + ; // this list of tracker loggers serves as tracker_callbacks when // shutting down. This list is just here to keep them alive during @@ -1214,7 +1222,11 @@ namespace libtorrent void tracker_request_error(tracker_request const& r , int response_code, error_code const& ec, const std::string& str , int retry_interval); - void debug_log(const char* fmt, ...) const; + void debug_log(const char* fmt, ...) const +#if defined __GNUC__ || defined __clang__ + __attribute__((format(printf, 2, 3))) +#endif + ; session_interface& m_ses; }; #endif diff --git a/include/libtorrent/aux_/session_interface.hpp b/include/libtorrent/aux_/session_interface.hpp index 456c96565..d63322e14 100644 --- a/include/libtorrent/aux_/session_interface.hpp +++ b/include/libtorrent/aux_/session_interface.hpp @@ -109,8 +109,16 @@ namespace libtorrent { namespace aux struct session_logger { #ifndef TORRENT_DISABLE_LOGGING - virtual void session_log(char const* fmt, ...) const = 0; - virtual void session_vlog(char const* fmt, va_list& va) const = 0; + virtual void session_log(char const* fmt, ...) const +#if defined __GNUC__ || defined __clang__ + __attribute__((format(printf, 2, 3))) +#endif + = 0; + virtual void session_vlog(char const* fmt, va_list& va) const +#if defined __GNUC__ || defined __clang__ + __attribute__((format(printf, 2, 0))) +#endif + = 0; #endif #if TORRENT_USE_ASSERTS diff --git a/include/libtorrent/extensions/ut_pex.hpp b/include/libtorrent/extensions/ut_pex.hpp index 1b23261a9..64b5941e4 100644 --- a/include/libtorrent/extensions/ut_pex.hpp +++ b/include/libtorrent/extensions/ut_pex.hpp @@ -33,18 +33,22 @@ POSSIBILITY OF SUCH DAMAGE. #ifndef TORRENT_UT_PEX_EXTENSION_HPP_INCLUDED #define TORRENT_UT_PEX_EXTENSION_HPP_INCLUDED +#include "libtorrent/config.hpp" + #ifndef TORRENT_DISABLE_EXTENSIONS +#include "libtorrent/socket.hpp" // for endpoint + #include "libtorrent/aux_/disable_warnings_push.hpp" #include -#include "libtorrent/config.hpp" #include "libtorrent/aux_/disable_warnings_pop.hpp" namespace libtorrent { struct torrent_plugin; + struct peer_plugin; class torrent; // constructor function for the ut_pex extension. The ut_pex @@ -56,6 +60,8 @@ namespace libtorrent // This can either be passed in the add_torrent_params::extensions field, or // via torrent_handle::add_extension(). TORRENT_EXPORT boost::shared_ptr create_ut_pex_plugin(torrent*, void*); + + bool was_introduced_by(peer_plugin const* pp, tcp::endpoint const& ep); } #endif // TORRENT_DISABLE_EXTENSIONS diff --git a/include/libtorrent/file_storage.hpp b/include/libtorrent/file_storage.hpp index 44ea3d579..f54e147fe 100644 --- a/include/libtorrent/file_storage.hpp +++ b/include/libtorrent/file_storage.hpp @@ -309,7 +309,7 @@ namespace libtorrent #ifndef TORRENT_NO_DEPRECATE TORRENT_DEPRECATED - void add_file(file_entry const& fe, char const* infohash = NULL); + void add_file(file_entry const& fe, char const* filehash = NULL); #if TORRENT_USE_WSTRING // all wstring APIs are deprecated since 0.16.11 diff --git a/include/libtorrent/http_tracker_connection.hpp b/include/libtorrent/http_tracker_connection.hpp index cb5da1332..f2ea8640d 100644 --- a/include/libtorrent/http_tracker_connection.hpp +++ b/include/libtorrent/http_tracker_connection.hpp @@ -98,6 +98,10 @@ namespace libtorrent TORRENT_EXTRA_EXPORT tracker_response parse_tracker_response( char const* data, int size, error_code& ec , bool scrape_request, sha1_hash scrape_ih); + + // TODO: 3 add a unit test for this function + TORRENT_EXTRA_EXPORT bool extract_peer_info(bdecode_node const& info + , peer_entry& ret, error_code& ec); } #endif // TORRENT_HTTP_TRACKER_CONNECTION_HPP_INCLUDED diff --git a/include/libtorrent/lsd.hpp b/include/libtorrent/lsd.hpp index e209482e9..a6e61d286 100644 --- a/include/libtorrent/lsd.hpp +++ b/include/libtorrent/lsd.hpp @@ -95,7 +95,11 @@ private: #endif #ifndef TORRENT_DISABLE_LOGGING log_callback_t m_log_cb; - void debug_log(char const* fmt, ...) const; + void debug_log(char const* fmt, ...) const +#if defined __GNUC__ || defined __clang__ + __attribute__((format(printf, 2, 3))) +#endif + ; #endif // used to resend udp packets in case diff --git a/include/libtorrent/peer_connection.hpp b/include/libtorrent/peer_connection.hpp index 464771571..21fc84e90 100644 --- a/include/libtorrent/peer_connection.hpp +++ b/include/libtorrent/peer_connection.hpp @@ -548,7 +548,11 @@ namespace libtorrent int est_reciprocation_rate() const { return m_est_reciprocation_rate; } #ifndef TORRENT_DISABLE_LOGGING - virtual void peer_log(char const* fmt, ...) const; + virtual void peer_log(char const* fmt, ...) const +#if defined __GNUC__ || defined __clang__ + __attribute__((format(printf, 2, 3))) +#endif + ; #endif #ifndef TORRENT_DISABLE_LOGGING diff --git a/include/libtorrent/peer_info.hpp b/include/libtorrent/peer_info.hpp index 5f8054336..8cc343bb8 100644 --- a/include/libtorrent/peer_info.hpp +++ b/include/libtorrent/peer_info.hpp @@ -452,8 +452,6 @@ namespace libtorrent boost::uint8_t source; }; - // defined in policy.cpp - int source_rank(int source_bitmask); } #endif // TORRENT_PEER_INFO_HPP_INCLUDED diff --git a/include/libtorrent/peer_list.hpp b/include/libtorrent/peer_list.hpp index d85c6d796..93f859be0 100644 --- a/include/libtorrent/peer_list.hpp +++ b/include/libtorrent/peer_list.hpp @@ -36,6 +36,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include "libtorrent/string_util.hpp" // for allocate_string_copy +#include "libtorrent/request_blocks.hpp" // for source_rank #include "libtorrent/torrent_peer.hpp" #include "libtorrent/piece_picker.hpp" diff --git a/include/libtorrent/request_blocks.hpp b/include/libtorrent/request_blocks.hpp index 04bc4cedf..3e65d2d18 100644 --- a/include/libtorrent/request_blocks.hpp +++ b/include/libtorrent/request_blocks.hpp @@ -43,6 +43,12 @@ namespace libtorrent // shouldn't be incremented, since it won't use any significant // amount of CPU bool request_a_block(torrent& t, peer_connection& c); + + // returns the rank of a peer's source. We have an affinity + // to connecting to peers with higher rank. This is to avoid + // problems when our peer list is diluted by stale peers from + // the resume data for instance + int source_rank(int source_bitmask); } #endif diff --git a/include/libtorrent/session.hpp b/include/libtorrent/session.hpp index 50fa6f5a1..63d18c032 100644 --- a/include/libtorrent/session.hpp +++ b/include/libtorrent/session.hpp @@ -139,6 +139,7 @@ namespace libtorrent // given a name of a metric, this function returns the counter index of it, // or -1 if it could not be found. The counter index is the index into the // values array returned by session_stats_alert. + // TODO: 3 move this declaration into its own header (session_stats.hpp) TORRENT_EXPORT int find_metric_idx(char const* name); void TORRENT_EXPORT TORRENT_CFG(); diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index d37020b2b..66e8a8ec1 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -1022,7 +1022,11 @@ namespace libtorrent // LOGGING #ifndef TORRENT_DISABLE_LOGGING - virtual void debug_log(const char* fmt, ...) const TORRENT_OVERRIDE; + virtual void debug_log(const char* fmt, ...) const TORRENT_OVERRIDE +#if defined __GNUC__ || defined __clang__ + __attribute__((format(printf, 2, 3))) +#endif + ; void log_to_all_peers(char const* message); time_point m_dht_start_time; #endif diff --git a/include/libtorrent/tracker_manager.hpp b/include/libtorrent/tracker_manager.hpp index 68de1badf..5d1cf0490 100644 --- a/include/libtorrent/tracker_manager.hpp +++ b/include/libtorrent/tracker_manager.hpp @@ -229,7 +229,11 @@ namespace libtorrent , int retry_interval) = 0; #ifndef TORRENT_DISABLE_LOGGING - virtual void debug_log(const char* fmt, ...) const = 0; + virtual void debug_log(const char* fmt, ...) const +#if defined __GNUC__ || defined __clang__ + __attribute__((format(printf, 2, 3))) +#endif + = 0; #endif }; diff --git a/src/disk_buffer_pool.cpp b/src/disk_buffer_pool.cpp index babfb67ca..cebde4fb7 100644 --- a/src/disk_buffer_pool.cpp +++ b/src/disk_buffer_pool.cpp @@ -218,19 +218,16 @@ namespace libtorrent #if TORRENT_HAVE_MMAP if (m_cache_pool) { - return buffer >= m_cache_pool && buffer < m_cache_pool + boost::uint64_t(m_max_use) * 0x4000; + return buffer >= m_cache_pool && buffer < m_cache_pool + + boost::uint64_t(m_max_use) * 0x4000; } #endif #if defined TORRENT_DEBUG return m_buffers_in_use.count(buffer) == 1; -#endif - -#ifdef TORRENT_DEBUG_BUFFERS +#elif defined TORRENT_DEBUG_BUFFERS return page_aligned_allocator::in_use(buffer); -#endif - -#ifdef TORRENT_DISABLE_POOL_ALLOCATOR +#elif defined TORRENT_DISABLE_POOL_ALLOCATOR return true; #else if (m_using_pool_allocator) diff --git a/src/file_storage.cpp b/src/file_storage.cpp index 5c2714910..220ea9f71 100644 --- a/src/file_storage.cpp +++ b/src/file_storage.cpp @@ -315,7 +315,7 @@ namespace libtorrent #ifndef TORRENT_NO_DEPRECATE - void file_storage::add_file(file_entry const& fe, char const* infohash) + void file_storage::add_file(file_entry const& fe, char const* filehash) { int flags = 0; if (fe.pad_file) flags |= file_storage::flag_pad_file; @@ -323,7 +323,7 @@ namespace libtorrent if (fe.executable_attribute) flags |= file_storage::flag_executable; if (fe.symlink_attribute) flags |= file_storage::flag_symlink; - add_file_borrow(NULL, 0, fe.path, fe.size, flags, NULL, fe.mtime + add_file_borrow(NULL, 0, fe.path, fe.size, flags, filehash, fe.mtime , fe.symlink_path); } @@ -866,7 +866,7 @@ namespace libtorrent , std::string const& save_path) const { int index = &fe - &m_files[0]; - return file_path(index); + return file_path(index, save_path); } std::string file_storage::file_name(internal_file_entry const& fe) const diff --git a/src/gzip.cpp b/src/gzip.cpp index ec0eb5b1b..c19f62681 100644 --- a/src/gzip.cpp +++ b/src/gzip.cpp @@ -214,12 +214,14 @@ namespace libtorrent { TORRENT_TRY { buffer.resize(destlen); - } TORRENT_CATCH(std::exception& e) { + } TORRENT_CATCH(std::exception&) { ec = errors::no_memory; return; } - ret = puff((unsigned char*)&buffer[0], &destlen, (unsigned char*)in, &srclen); + ret = puff(reinterpret_cast(&buffer[0]), &destlen + , const_cast( + reinterpret_cast(in)), &srclen); // if the destination buffer wasn't large enough, double its // size and try again. Unless it's already at its max, in which @@ -233,7 +235,7 @@ namespace libtorrent } destlen *= 2; - if (destlen > (unsigned int)maximum_size) + if (destlen > boost::uint32_t(maximum_size)) destlen = maximum_size; } } while (ret == 1); diff --git a/src/lsd.cpp b/src/lsd.cpp index c8ad8b3b3..2cef814b2 100644 --- a/src/lsd.cpp +++ b/src/lsd.cpp @@ -42,6 +42,8 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/debug.hpp" #endif +#include "libtorrent/aux_/disable_warnings_push.hpp" + #include #include #if BOOST_VERSION < 103500 @@ -55,13 +57,27 @@ POSSIBILITY OF SUCH DAMAGE. #include #include -using namespace libtorrent; +#include "libtorrent/aux_/disable_warnings_pop.hpp" namespace libtorrent { // defined in broadcast_socket.cpp address guess_local_address(io_service&); + +namespace { + +int render_lsd_packet(char* dst, int len, int listen_port + , char const* info_hash_hex, int m_cookie, char const* host) +{ + return snprintf(dst, len, + "BT-SEARCH * HTTP/1.1\r\n" + "Host: %s:6771\r\n" + "Port: %d\r\n" + "Infohash: %s\r\n" + "cookie: %x\r\n" + "\r\n\r\n", host, listen_port, info_hash_hex, m_cookie); } +} // anonymous namespace static error_code ec; @@ -88,6 +104,9 @@ lsd::lsd(io_service& ios, peer_callback_t const& cb } #ifndef TORRENT_DISABLE_LOGGING +#if defined __GNUC__ || defined __clang__ +__attribute__((format(printf, 2, 3))) +#endif void lsd::debug_log(char const* fmt, ...) const { va_list v; @@ -114,18 +133,6 @@ void lsd::start(error_code& ec) lsd::~lsd() {} -int render_lsd_packet(char* dst, int len, int listen_port - , char const* info_hash_hex, int m_cookie, char const* host) -{ - return snprintf(dst, len, - "BT-SEARCH * HTTP/1.1\r\n" - "Host: %s:6771\r\n" - "Port: %d\r\n" - "Infohash: %s\r\n" - "cookie: %x\r\n" - "\r\n\r\n", host, listen_port, info_hash_hex, m_cookie); -} - void lsd::announce(sha1_hash const& ih, int listen_port, bool broadcast) { announce_impl(ih, listen_port, broadcast, 0); @@ -314,3 +321,6 @@ void lsd::close() m_callback.clear(); } +} // libtorrent namespace + + diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index fec804677..a2e20524f 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -516,6 +516,9 @@ namespace libtorrent } #ifndef TORRENT_DISABLE_LOGGING +#if defined __GNUC__ || defined __clang__ + __attribute__((format(printf, 2, 3))) +#endif void peer_connection::peer_log(char const* fmt, ...) const { TORRENT_ASSERT(is_single_thread()); @@ -5696,6 +5699,8 @@ namespace libtorrent void peer_connection::send_buffer(char const* buf, int size, int flags) { TORRENT_ASSERT(is_single_thread()); + TORRENT_UNUSED(flags); + int free_space = m_send_buffer.space_in_last_buffer(); if (free_space > size) free_space = size; if (free_space > 0) diff --git a/src/platform_util.cpp b/src/platform_util.cpp index aa3628da3..000a0e498 100644 --- a/src/platform_util.cpp +++ b/src/platform_util.cpp @@ -31,6 +31,10 @@ POSSIBILITY OF SUCH DAMAGE. */ #include "libtorrent/config.hpp" +#include "libtorrent/platform_util.hpp" + +#include "libtorrent/aux_/disable_warnings_push.hpp" + #include #if TORRENT_USE_RLIMIT @@ -46,6 +50,8 @@ POSSIBILITY OF SUCH DAMAGE. #include #endif +#include "libtorrent/aux_/disable_warnings_pop.hpp" + namespace libtorrent { diff --git a/src/puff.cpp b/src/puff.cpp index 82347e779..8074fef38 100644 --- a/src/puff.cpp +++ b/src/puff.cpp @@ -70,6 +70,10 @@ All "short" has been replaced with boost::int16_t and all "long" with boost::int32_t according to the type width assuptions in the comment above. */ + +// this whole file is just preserved and warnings are suppressed +#include "libtorrent/aux_/disable_warnings_push.hpp" + #include /* for setjmp(), longjmp(), and jmp_buf */ #include /* for types with size guarantees */ #include "libtorrent/puff.hpp" /* prototype for puff() */ @@ -840,3 +844,6 @@ int main(int argc, char **argv) return ret; } #endif + +#include "libtorrent/aux_/disable_warnings_pop.hpp" + diff --git a/src/request_blocks.cpp b/src/request_blocks.cpp index 995c97bb3..937b1da51 100644 --- a/src/request_blocks.cpp +++ b/src/request_blocks.cpp @@ -36,15 +36,12 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/socket_type.hpp" #include "libtorrent/peer_info.hpp" // for peer_info flags #include "libtorrent/performance_counters.hpp" // for counters +#include "libtorrent/request_blocks.hpp" #include namespace libtorrent { - // returns the rank of a peer's source. We have an affinity - // to connecting to peers with higher rank. This is to avoid - // problems when our peer list is diluted by stale peers from - // the resume data for instance int source_rank(int source_bitmask) { int ret = 0; diff --git a/src/session_impl.cpp b/src/session_impl.cpp index efe41905a..be1b7df1e 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -4247,6 +4247,8 @@ retry: } #endif //TORRENT_DISABLE_MUTABLE_TORRENTS + namespace { + // returns true if lhs is a better disconnect candidate than rhs bool compare_disconnect_torrent(session_impl::torrent_map::value_type const& lhs , session_impl::torrent_map::value_type const& rhs) @@ -4264,6 +4266,8 @@ retry: return lhs.second->num_peers() > rhs.second->num_peers(); } + } // anonymous namespace + boost::weak_ptr session_impl::find_disconnect_candidate_torrent() const { aux::session_impl::torrent_map::const_iterator i = std::min_element(m_torrents.begin(), m_torrents.end() @@ -4276,6 +4280,9 @@ retry: } #ifndef TORRENT_DISABLE_LOGGING +#if defined __GNUC__ || defined __clang__ + __attribute__((format(printf, 2, 3))) +#endif void session_impl::session_log(char const* fmt, ...) const { if (!m_alerts.should_post()) return; @@ -4286,6 +4293,9 @@ retry: va_end(v); } +#if defined __GNUC__ || defined __clang__ + __attribute__((format(printf, 2, 0))) +#endif void session_impl::session_vlog(char const* fmt, va_list& v) const { if (!m_alerts.should_post()) return; diff --git a/src/session_stats.cpp b/src/session_stats.cpp index 30b47fb93..a67876f35 100644 --- a/src/session_stats.cpp +++ b/src/session_stats.cpp @@ -518,6 +518,8 @@ namespace libtorrent }; #undef METRIC + // TODO: 3 create a header for this file and declare these two functions. + // currently this is externed into session.cpp void get_stats_metric_map(std::vector& stats) { const int num = sizeof(metrics)/sizeof(metrics[0]); diff --git a/src/torrent.cpp b/src/torrent.cpp index 5051b3384..a66fd2f2b 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -3166,7 +3166,7 @@ namespace libtorrent } void torrent::tracker_scrape_response(tracker_request const& req - , int complete, int incomplete, int downloaded, int downloaders) + , int complete, int incomplete, int downloaded, int /* downloaders */) { TORRENT_ASSERT(is_single_thread()); @@ -4931,7 +4931,7 @@ namespace libtorrent } } - void torrent::on_torrent_paused(disk_io_job const* j) + void torrent::on_torrent_paused(disk_io_job const*) { TORRENT_ASSERT(is_single_thread()); @@ -8895,12 +8895,16 @@ namespace libtorrent } } + namespace { + int clamped_subtract(int a, int b) { if (a < b) return 0; return a - b; } + } // anonymous namespace + // this is called every time the session timer takes a step back. Since the // session time is meant to fit in 16 bits, it only covers a range of // about 18 hours. This means every few hours the whole epoch of this @@ -9118,7 +9122,7 @@ namespace libtorrent , boost::bind(&torrent::on_cache_flushed, shared_from_this(), _1)); } - void torrent::on_cache_flushed(disk_io_job const* j) + void torrent::on_cache_flushed(disk_io_job const*) { dec_refcount("release_files"); TORRENT_ASSERT(is_single_thread()); @@ -11646,6 +11650,9 @@ namespace libtorrent } #ifndef TORRENT_DISABLE_LOGGING +#if defined __GNUC__ || defined __clang__ + __attribute__((format(printf, 2, 3))) +#endif void torrent::debug_log(char const* fmt, ...) const { if (!alerts().should_post()) return; diff --git a/src/ut_pex.cpp b/src/ut_pex.cpp index 8ac29742e..163e93f2b 100644 --- a/src/ut_pex.cpp +++ b/src/ut_pex.cpp @@ -30,6 +30,8 @@ POSSIBILITY OF SUCH DAMAGE. */ +#include "libtorrent/config.hpp" + #ifndef TORRENT_DISABLE_EXTENSIONS #include "libtorrent/aux_/disable_warnings_push.hpp"