fix more warnings

This commit is contained in:
Arvid Norberg 2015-04-21 04:30:34 +00:00
parent 3951377d95
commit 0b063de9ff
25 changed files with 143 additions and 46 deletions

View File

@ -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

View File

@ -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

View File

@ -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 <boost/shared_ptr.hpp>
#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<torrent_plugin> create_ut_pex_plugin(torrent*, void*);
bool was_introduced_by(peer_plugin const* pp, tcp::endpoint const& ep);
}
#endif // TORRENT_DISABLE_EXTENSIONS

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -36,6 +36,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <algorithm>
#include <deque>
#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"

View File

@ -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

View File

@ -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();

View File

@ -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

View File

@ -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
};

View File

@ -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)

View File

@ -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

View File

@ -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<unsigned char*>(&buffer[0]), &destlen
, const_cast<unsigned char*>(
reinterpret_cast<const unsigned char*>(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);

View File

@ -42,6 +42,8 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/debug.hpp"
#endif
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/bind.hpp>
#include <boost/ref.hpp>
#if BOOST_VERSION < 103500
@ -55,13 +57,27 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/config.hpp>
#include <cstdarg>
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

View File

@ -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)

View File

@ -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 <boost/cstdint.hpp>
#if TORRENT_USE_RLIMIT
@ -46,6 +50,8 @@ POSSIBILITY OF SUCH DAMAGE.
#include <windows.h>
#endif
#include "libtorrent/aux_/disable_warnings_pop.hpp"
namespace libtorrent
{

View File

@ -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 <setjmp.h> /* for setjmp(), longjmp(), and jmp_buf */
#include <boost/cstdint.hpp> /* 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"

View File

@ -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 <vector>
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;

View File

@ -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<torrent> 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<log_alert>()) 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<log_alert>()) return;

View File

@ -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_metric>& stats)
{
const int num = sizeof(metrics)/sizeof(metrics[0]);

View File

@ -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<torrent_log_alert>()) return;

View File

@ -30,6 +30,8 @@ POSSIBILITY OF SUCH DAMAGE.
*/
#include "libtorrent/config.hpp"
#ifndef TORRENT_DISABLE_EXTENSIONS
#include "libtorrent/aux_/disable_warnings_push.hpp"