fixed a whole bunch of build warnings on gcc and msvc, along with some fixes discovered along the way

This commit is contained in:
Arvid Norberg 2011-02-21 05:24:41 +00:00
parent 9fe69e7596
commit 141ada013f
73 changed files with 353 additions and 248 deletions

View File

@ -774,7 +774,7 @@ void scan_dir(std::string const& dir_path
torrent_status const& get_active_torrent(std::vector<torrent_status> const& torrents)
{
if (active_torrent >= torrents.size()
if (active_torrent >= int(torrents.size())
|| active_torrent < 0) active_torrent = 0;
std::vector<torrent_status>::const_iterator i = torrents.begin();
std::advance(i, active_torrent);
@ -817,7 +817,7 @@ int save_file(std::string const& filename, std::vector<char>& v)
if (ec) return -1;
file::iovec_t b = {&v[0], v.size()};
size_type written = f.writev(0, &b, 1, ec);
if (written != v.size()) return -3;
if (written != int(v.size())) return -3;
if (ec) return -3;
return 0;
}
@ -1153,7 +1153,12 @@ int main(int argc, char* argv[])
ses.set_proxy(ps);
ses.listen_on(std::make_pair(listen_port, listen_port + 10)
, bind_to_interface.c_str());
, ec, bind_to_interface.c_str());
if (ec)
{
fprintf(stderr, "failed to listen on %s on ports %d-%d: %s\n"
, bind_to_interface.c_str(), listen_port, listen_port+1, ec.message().c_str());
}
#ifndef TORRENT_DISABLE_DHT
if (start_dht)
@ -1241,7 +1246,7 @@ int main(int argc, char* argv[])
handles.clear();
memset(counters, 0, sizeof(counters));
ses.get_torrent_status(&handles, boost::bind(&show_torrent, _1, torrent_filter, (int*)counters));
if (active_torrent >= handles.size()) active_torrent = handles.size() - 1;
if (active_torrent >= int(handles.size())) active_torrent = handles.size() - 1;
std::sort(handles.begin(), handles.end(), &compare_torrent);
@ -1272,7 +1277,7 @@ int main(int argc, char* argv[])
handles.clear();
memset(counters, 0, sizeof(counters));
ses.get_torrent_status(&handles, boost::bind(&show_torrent, _1, torrent_filter, (int*)counters));
if (active_torrent >= handles.size()) active_torrent = handles.size() - 1;
if (active_torrent >= int(handles.size())) active_torrent = handles.size() - 1;
std::sort(handles.begin(), handles.end(), &compare_torrent);
}
}
@ -1285,7 +1290,7 @@ int main(int argc, char* argv[])
handles.clear();
memset(counters, 0, sizeof(counters));
ses.get_torrent_status(&handles, boost::bind(&show_torrent, _1, torrent_filter, (int*)counters));
if (active_torrent >= handles.size()) active_torrent = handles.size() - 1;
if (active_torrent >= int(handles.size())) active_torrent = handles.size() - 1;
std::sort(handles.begin(), handles.end(), &compare_torrent);
}
}
@ -1299,7 +1304,7 @@ int main(int argc, char* argv[])
{
// arrow down
++active_torrent;
if (active_torrent >= handles.size()) active_torrent = handles.size() - 1;
if (active_torrent >= int(handles.size())) active_torrent = handles.size() - 1;
}
}
@ -1469,7 +1474,7 @@ int main(int argc, char* argv[])
"[5] toggle peer rate [6] toggle failures [7] toggle send buffers [R] save resume data\n";
char const* filter_names[] = { "all", "downloading", "non-paused", "seeding", "queued", "stopped", "checking"};
for (int i = 0; i < sizeof(filter_names)/sizeof(filter_names[0]); ++i)
for (int i = 0; i < int(sizeof(filter_names)/sizeof(filter_names[0])); ++i)
{
char filter[200];
snprintf(filter, sizeof(filter), "%s[%s (%d)]%s", torrent_filter == i?esc("7"):""

View File

@ -61,7 +61,7 @@ struct peer_conn
, outstanding_requests(0)
{
// build a list of all pieces and request them all!
for (int i = 0; i < pieces.size(); ++i)
for (int i = 0; i < int(pieces.size()); ++i)
pieces[i] = i;
std::random_shuffle(pieces.begin(), pieces.end());

View File

@ -49,7 +49,7 @@ int save_file(std::string const& filename, std::vector<char>& v)
if (ec) return -1;
file::iovec_t b = {&v[0], v.size()};
size_type written = f.writev(0, &b, 1, ec);
if (written != v.size()) return -3;
if (written != int(v.size())) return -3;
if (ec) return -3;
return 0;
}

View File

@ -47,10 +47,15 @@ int main(int argc, char* argv[])
}
session s;
s.listen_on(std::make_pair(6881, 6889));
error_code ec;
s.listen_on(std::make_pair(6881, 6889), ec);
if (ec)
{
fprintf(stderr, "failed to open listen socket: %s\n", ec.message().c_str());
return 1;
}
add_torrent_params p;
p.save_path = "./";
error_code ec;
p.ti = new torrent_info(argv[1], ec);
if (ec)
{

View File

@ -35,11 +35,12 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/cstdint.hpp>
#include "libtorrent/peer_id.hpp" // for sha1_hash
#include "libtorrent/config.hpp" // for sha1_hash
namespace libtorrent
{
void set_bit(boost::uint32_t b, boost::uint8_t* bits, int len);
bool has_bit(boost::uint32_t b, boost::uint8_t const* bits, int len);
TORRENT_EXPORT void set_bit(boost::uint32_t b, boost::uint8_t* bits, int len);
TORRENT_EXPORT bool has_bit(boost::uint32_t b, boost::uint8_t const* bits, int len);
template <int N>
struct bloom_filter

View File

@ -389,14 +389,14 @@ private:
#ifndef TORRENT_DISABLE_EXTENSIONS
// the message ID for upload only message
// 0 if not supported
int m_upload_only_id;
boost::uint8_t m_upload_only_id;
// the message ID for holepunch messages
int m_holepunch_id;
boost::uint8_t m_holepunch_id;
// the message ID for share mode message
// 0 if not supported
int m_share_mode_id;
boost::uint8_t m_share_mode_id;
char m_reserved_bits[8];
#endif

View File

@ -118,6 +118,7 @@ public:
{
if (&b == this) return *this;
resize(b.size());
if (b.size() == 0) return *this;
std::memcpy(m_begin, b.begin(), b.size());
return *this;
}

View File

@ -93,6 +93,13 @@ POSSIBILITY OF SUCH DAMAGE.
#pragma warning(disable: 4258)
#pragma warning(disable: 4251)
// class X needs to have dll-interface to be used by clients of class Y
#pragma warning(disable:4251)
// '_vsnprintf': This function or variable may be unsafe
#pragma warning(disable:4996)
// 'strdup': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _strdup
#pragma warning(disable: 4996)
# if defined(TORRENT_BUILDING_SHARED)
# define TORRENT_EXPORT __declspec(dllexport)
# elif defined(TORRENT_LINKING_SHARED)
@ -223,11 +230,6 @@ POSSIBILITY OF SUCH DAMAGE.
#if defined TORRENT_WINDOWS && !defined TORRENT_MINGW
// class X needs to have dll-interface to be used by clients of class Y
#pragma warning(disable:4251)
// '_vsnprintf': This function or variable may be unsafe
#pragma warning(disable:4996)
#include <stdarg.h>
inline int snprintf(char* buf, int len, char const* fmt, ...)
@ -323,6 +325,10 @@ inline int snprintf(char* buf, int len, char const* fmt, ...)
#define TORRENT_USE_I2P 1
#endif
#ifndef TORRENT_HAS_STRDUP
#define TORRENT_HAS_STRDUP 1
#endif
#if !defined(TORRENT_READ_HANDLER_MAX_SIZE)
# define TORRENT_READ_HANDLER_MAX_SIZE 256
#endif
@ -368,5 +374,16 @@ inline int snprintf(char* buf, int len, char const* fmt, ...)
#endif
#if !TORRENT_HAS_STRDUP
inline char* strdup(char const* str)
{
if (str == 0) return 0;
char* tmp = (char*)malloc(strlen(str) + 1);
if (tmp == 0) return 0;
strcpy(tmp, str);
return tmp;
}
#endif
#endif // TORRENT_CONFIG_HPP_INCLUDED

View File

@ -163,6 +163,7 @@ namespace libtorrent
, blocks_read(0)
, blocks_read_hit(0)
, reads(0)
, queued_bytes(0)
, cache_size(0)
, read_cache_size(0)
, total_used_buffers(0)

View File

@ -80,6 +80,9 @@ struct TORRENT_EXPORT http_connection : boost::enable_shared_from_this<http_conn
, http_connect_handler const& ch = http_connect_handler()
, http_filter_handler const& fh = http_filter_handler())
: m_sock(ios)
#if TORRENT_USE_I2P
, m_i2p_conn(0)
#endif
, m_read_pos(0)
, m_resolver(ios)
, m_handler(handler)

View File

@ -146,7 +146,7 @@ namespace libtorrent
// while reading a chunk, this is the offset where the
// current chunk will end (it refers to the first character
// in the chunk tail header or the next chunk header)
int m_cur_chunk_end;
size_type m_cur_chunk_end;
// the sum of all chunk headers read so far
int m_chunk_header_size;

View File

@ -120,7 +120,7 @@ namespace libtorrent
// the number of bytes left to receive of the response we're
// currently parsing
int m_response_left;
size_type m_response_left;
// this is the offset inside the current receive
// buffer where the next chunk header will be.
@ -128,7 +128,7 @@ namespace libtorrent
// parsed. It does not necessarily point to a valid
// offset in the receive buffer, if we haven't received
// it yet. This offset never includes the HTTP header
int m_chunk_pos;
size_type m_chunk_pos;
// this is the number of bytes we've already received
// from the next chunk header we're waiting for

View File

@ -52,15 +52,15 @@ namespace libtorrent
friend void intrusive_ptr_add_ref(intrusive_ptr_base<T> const* s)
{
TORRENT_ASSERT(s->m_refs >= 0);
TORRENT_ASSERT(s != 0);
TORRENT_ASSERT(s->m_refs >= 0);
++s->m_refs;
}
friend void intrusive_ptr_release(intrusive_ptr_base<T> const* s)
{
TORRENT_ASSERT(s->m_refs > 0);
TORRENT_ASSERT(s != 0);
TORRENT_ASSERT(s->m_refs > 0);
if (--s->m_refs == 0)
boost::checked_delete(static_cast<T const*>(s));
}

View File

@ -56,7 +56,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/socket.hpp"
namespace libtorrent {
struct alert_manager;
class alert_manager;
}
namespace libtorrent { namespace dht
@ -302,11 +302,6 @@ protected:
dht_settings const& m_settings;
// the maximum number of peers to send in a get_peers
// reply. Ordinary trackers usually limit this to 50.
// 50 => 6 * 50 = 250 bytes + packet overhead
int m_max_peers_reply;
private:
typedef libtorrent::mutex mutex_t;
mutex_t m_mutex;

View File

@ -73,6 +73,8 @@ struct observer : boost::noncopyable
, m_refs(0)
, m_algorithm(a)
, m_id(id)
, m_port(0)
, m_transaction_id()
, flags(0)
{
TORRENT_ASSERT(a);
@ -92,7 +94,7 @@ struct observer : boost::noncopyable
// a few seconds, before the request has timed out
void short_timeout();
bool has_short_timeout() const { return flags & flag_short_timeout; }
bool has_short_timeout() const { return (flags & flag_short_timeout) != 0; }
// this is called when no reply has been received within
// some timeout

View File

@ -87,7 +87,7 @@ namespace libtorrent
none_t, dict_t, list_t, string_t, int_t
};
lazy_entry() : m_begin(0), m_len(0), m_type(none_t)
lazy_entry() : m_begin(0), m_len(0), m_size(0), m_capacity(0), m_type(none_t)
{ m_data.start = 0; }
entry_type_t type() const { return (entry_type_t)m_type; }

View File

@ -41,7 +41,7 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent
{
struct torrent_handle;
struct session;
class session;
std::string TORRENT_EXPORT make_magnet_uri(torrent_handle const& handle);
std::string TORRENT_EXPORT make_magnet_uri(torrent_info const& info);

View File

@ -116,6 +116,12 @@ namespace libtorrent
TORRENT_ASSERT(n >= 0);
if (n > number_size * 8) n = number_size;
int num_bytes = n / 8;
if (num_bytes >= number_size)
{
std::memset(m_number, 0, number_size);
return *this;
}
if (num_bytes > 0)
{
std::memmove(m_number, m_number + num_bytes, number_size - num_bytes);
@ -136,6 +142,11 @@ namespace libtorrent
big_number& operator>>=(int n)
{
int num_bytes = n / 8;
if (num_bytes >= number_size)
{
std::memset(m_number, 0, number_size);
return *this;
}
if (num_bytes > 0)
{
std::memmove(m_number + num_bytes, m_number, number_size - num_bytes);

View File

@ -146,7 +146,9 @@ namespace libtorrent
struct downloading_piece
{
downloading_piece(): finished(0), writing(0), requested(0) {}
downloading_piece(): state(none), index(-1), info(0)
, finished(0), writing(0), requested(0) {}
piece_state_t state;
// the index of the piece

View File

@ -52,6 +52,7 @@ public:
explicit proxy_base(io_service& io_service)
: m_sock(io_service)
, m_port(0)
, m_resolver(io_service)
{}

View File

@ -91,6 +91,8 @@ namespace libtorrent
struct feed_status
{
feed_status(): last_update(0), next_update(0)
, updating(false), ttl(0) {}
std::string url;
std::string title;
std::string description;
@ -119,7 +121,7 @@ namespace libtorrent
};
struct feed_state;
struct http_parser;
class http_parser;
boost::shared_ptr<feed> new_feed(aux::session_impl& ses, feed_settings const& sett);

View File

@ -87,13 +87,9 @@ namespace libtorrent
// hardware exceptions that makes
// it hard to debug stuff
#ifdef _MSC_VER
struct eh_initializer
struct TORRENT_EXPORT eh_initializer
{
eh_initializer()
{
::_set_se_translator(straight_to_debugger);
}
eh_initializer();
static void straight_to_debugger(unsigned int, _EXCEPTION_POINTERS*)
{ throw; }
};

View File

@ -39,7 +39,7 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent
{
struct lazy_entry;
struct entry;
class entry;
enum { std_string, character, integer
, floating_point, boolean, size_integer

View File

@ -286,7 +286,6 @@ namespace libtorrent
error_code const& error() const { return m_storage->error(); }
std::string const& error_file() const { return m_storage->error_file(); }
int last_piece() const { return m_last_piece; }
int last_operation() const { return m_last_op; }
void clear_error() { m_storage->clear_error(); }
int slot_for(int piece) const;
@ -424,9 +423,6 @@ namespace libtorrent
// the last piece we wrote to or read from
int m_last_piece;
// the last operation we did (read or write)
int m_last_op;
// this is saved in case we need to instantiate a new
// storage (osed when remapping files)
storage_constructor_type m_storage_constructor;

View File

@ -80,7 +80,7 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent
{
struct http_parser;
class http_parser;
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
struct logger;
@ -93,7 +93,7 @@ namespace libtorrent
struct tracker_request;
struct add_torrent_params;
struct storage_interface;
struct bt_peer_connection;
class bt_peer_connection;
namespace aux
{
@ -237,7 +237,7 @@ namespace libtorrent
void handle_disk_error(disk_io_job const& j, peer_connection* c = 0);
void clear_error();
void set_error(error_code const& ec, std::string const& file);
bool has_error() const { return m_error; }
bool has_error() const { return !!m_error; }
error_code error() const { return m_error; }
void flush_cache();
@ -731,7 +731,14 @@ namespace libtorrent
// --------------------------------------------
// RESOURCE MANAGEMENT
void add_free_upload(int diff) { m_available_free_upload += diff; }
void add_free_upload(size_type diff)
{
TORRENT_ASSERT(diff >= 0);
if (UINT_MAX - m_available_free_upload > diff)
m_available_free_upload += boost::uint32_t(diff);
else
m_available_free_upload = UINT_MAX;
}
int get_peer_upload_limit(tcp::endpoint ip) const;
int get_peer_download_limit(tcp::endpoint ip) const;

View File

@ -439,10 +439,13 @@ namespace libtorrent
, num_incomplete(-1)
, list_seeds(0)
, list_peers(0)
, connect_candidates(0)
, num_pieces(0)
, total_done(0)
, total_wanted_done(0)
, total_wanted(0)
, distributed_full_copies(0)
, distributed_fraction(0)
, distributed_copies(0.f)
, block_size(0)
, num_uploads(0)
@ -471,6 +474,7 @@ namespace libtorrent
, time_since_upload(0)
, time_since_download(0)
, queue_position(0)
, need_save_resume(false)
{}
// handle to the torrent

View File

@ -84,6 +84,7 @@ namespace libtorrent
, left(-1)
, corrupt(0)
, redundant(0)
, listen_port(0)
, event(none)
, key(0)
, num_want(0)

View File

@ -218,6 +218,7 @@ private:
struct rootdevice
{
rootdevice(): service_namespace(0)
, port(0)
, lease_duration(default_lease_time)
, supports_specific_external(true)
, disabled(false)

View File

@ -126,10 +126,10 @@ namespace libtorrent
// the number of bytes received in the current HTTP
// response. used to know where in the buffer the
// next response starts
int m_received_body;
size_type m_received_body;
// position in the current range response
int m_range_pos;
size_type m_range_pos;
// the position in the current block
int m_block_pos;
@ -140,7 +140,7 @@ namespace libtorrent
// parsed. It does not necessarily point to a valid
// offset in the receive buffer, if we haven't received
// it yet. This offset never includes the HTTP header
int m_chunk_pos;
size_type m_chunk_pos;
// this is the number of bytes we've already received
// from the next chunk header we're waiting for

View File

@ -36,7 +36,9 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent
{
bandwidth_channel::bandwidth_channel()
: m_quota_left(0)
: tmp(0)
, distribute_quota(0)
, m_quota_left(0)
, m_limit(0)
{}

View File

@ -35,7 +35,7 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent
{
bool has_bit(boost::uint32_t b, boost::uint8_t const* bits, int len)
{ b %= len * 8; return bits[b/8] & (1 << (b & 7)); }
{ b %= len * 8; return (bits[b/8] & (1 << (b & 7))) != 0; }
void set_bit(boost::uint32_t b, boost::uint8_t* bits, int len)
{ b %= len * 8; bits[b/8] |= (1 << (b & 7)); }

View File

@ -1665,7 +1665,7 @@ namespace libtorrent
if (extended_id == upload_only_msg)
{
if (!packet_finished()) return;
bool ul = detail::read_uint8(recv_buffer.begin);
bool ul = detail::read_uint8(recv_buffer.begin) != 0;
#ifdef TORRENT_VERBOSE_LOGGING
peer_log("<== UPLOAD_ONLY [ %s ]", (ul?"true":"false"));
#endif
@ -1676,7 +1676,7 @@ namespace libtorrent
if (extended_id == share_mode_msg)
{
if (!packet_finished()) return;
bool sm = detail::read_uint8(recv_buffer.begin);
bool sm = detail::read_uint8(recv_buffer.begin) != 0;
#ifdef TORRENT_VERBOSE_LOGGING
peer_log("<== SHARE_MODE [ %s ]", (sm?"true":"false"));
#endif
@ -1756,13 +1756,13 @@ namespace libtorrent
// upload_only
if (lazy_entry const* m = root.dict_find_dict("m"))
{
m_upload_only_id = m->dict_find_int_value("upload_only", 0);
m_holepunch_id = m->dict_find_int_value("ut_holepunch", 0);
m_upload_only_id = boost::uint8_t(m->dict_find_int_value("upload_only", 0));
m_holepunch_id = boost::uint8_t(m->dict_find_int_value("ut_holepunch", 0));
}
#endif
// there is supposed to be a remote listen port
int listen_port = root.dict_find_int_value("p");
int listen_port = int(root.dict_find_int_value("p"));
if (listen_port > 0 && peer_info_struct() != 0)
{
t->get_policy().update_peer_port(listen_port
@ -1772,13 +1772,13 @@ namespace libtorrent
// there should be a version too
// but where do we put that info?
int last_seen_complete = root.dict_find_int_value("complete_ago", -1);
int last_seen_complete = boost::uint8_t(root.dict_find_int_value("complete_ago", -1));
if (last_seen_complete >= 0) set_last_seen_complete(last_seen_complete);
std::string client_info = root.dict_find_string_value("v");
if (!client_info.empty()) m_client_version = client_info;
int reqq = root.dict_find_int_value("reqq");
int reqq = int(root.dict_find_int_value("reqq"));
if (reqq > 0) m_max_out_request_queue = reqq;
if (root.dict_find_int_value("upload_only", 0))
@ -2184,7 +2184,7 @@ namespace libtorrent
, end(m.end()); i != end; ++i)
{
if (i->second.type() != entry::int_t) continue;
int val = i->second.integer();
int val = int(i->second.integer());
TORRENT_ASSERT(ext.find(val) == ext.end());
ext.insert(val);
}
@ -3281,7 +3281,7 @@ namespace libtorrent
TORRENT_ASSERT(m_statistics.last_protocol_downloaded() - cur_protocol_dl >= 0);
size_type stats_diff = m_statistics.last_payload_downloaded() - cur_payload_dl +
m_statistics.last_protocol_downloaded() - cur_protocol_dl;
TORRENT_ASSERT(stats_diff == bytes_transferred);
TORRENT_ASSERT(stats_diff == size_type(bytes_transferred));
#endif
TORRENT_ASSERT(!packet_finished());
return;

View File

@ -124,7 +124,7 @@ namespace libtorrent
if (piece_size == 0 && !m_merkle_torrent)
{
const int target_size = 40 * 1024;
piece_size = fs.total_size() / (target_size / 20);
piece_size = int(fs.total_size() / (target_size / 20));
int i = 16*1024;
for (; i < 2*1024*1024; i *= 2)

View File

@ -771,14 +771,17 @@ namespace libtorrent
int block_size = (std::min)(piece_size - i * m_block_size, m_block_size);
TORRENT_ASSERT(offset + block_size <= piece_size);
TORRENT_ASSERT(offset + block_size > 0);
if (!buf)
if (iov)
{
TORRENT_ASSERT(!buf);
iov[iov_counter].iov_base = p.blocks[i].buf;
iov[iov_counter].iov_len = block_size;
++iov_counter;
}
else
{
TORRENT_ASSERT(buf);
TORRENT_ASSERT(iov == 0);
std::memcpy(buf.get() + offset, p.blocks[i].buf, block_size);
offset += m_block_size;
}
@ -963,7 +966,7 @@ namespace libtorrent
{
TORRENT_ASSERT(iov[i].iov_base);
TORRENT_ASSERT(iov[i].iov_len > 0);
TORRENT_ASSERT(offset + iov[i].iov_len <= buffer_size);
TORRENT_ASSERT(int(offset + iov[i].iov_len) <= buffer_size);
std::memcpy(iov[i].iov_base, buf.get() + offset, iov[i].iov_len);
offset += iov[i].iov_len;
}
@ -1496,19 +1499,19 @@ namespace libtorrent
bool should_cancel_on_abort(disk_io_job const& j)
{
TORRENT_ASSERT(j.action >= 0 && j.action < sizeof(action_flags));
TORRENT_ASSERT(j.action >= 0 && j.action < int(sizeof(action_flags)));
return action_flags[j.action] & cancel_on_abort;
}
bool is_read_operation(disk_io_job const& j)
{
TORRENT_ASSERT(j.action >= 0 && j.action < sizeof(action_flags));
TORRENT_ASSERT(j.action >= 0 && j.action < int(sizeof(action_flags)));
return action_flags[j.action] & read_operation;
}
bool operation_has_buffer(disk_io_job const& j)
{
TORRENT_ASSERT(j.action >= 0 && j.action < sizeof(action_flags));
TORRENT_ASSERT(j.action >= 0 && j.action < int(sizeof(action_flags)));
return action_flags[j.action] & buffer_operation;
}

View File

@ -333,7 +333,7 @@ namespace libtorrent
b1 = a1.to_v6().to_bytes();
b2 = a2.to_v6().to_bytes();
m = mask.to_v6().to_bytes();
for (int i = 0; i < b1.size(); ++i)
for (int i = 0; i < int(b1.size()); ++i)
b1[i] &= m[i];
return memcmp(&b1[0], &b2[0], b1.size()) == 0;
}

View File

@ -101,7 +101,7 @@ namespace libtorrent
bool is_space(char c)
{
const static char* ws = " \t\n\r\f\v";
return bool(std::strchr(ws, c));
return std::strchr(ws, c) != 0;
}
// generate a url-safe random string

View File

@ -303,6 +303,11 @@ namespace libtorrent
{
int num_read = read(infd, buffer, sizeof(buffer));
if (num_read == 0) break;
if (num_read < 0)
{
ec.assign(errno, boost::system::get_generic_category());
break;
}
int num_written = write(outfd, buffer, num_read);
if (num_written < num_read)
{
@ -728,6 +733,8 @@ namespace libtorrent
#endif
, m_open_mode(0)
{
// the return value is not important, since the
// error code contains the same information
open(path, mode, ec);
}
@ -795,6 +802,7 @@ namespace libtorrent
if (m_file_handle == INVALID_HANDLE_VALUE)
{
ec.assign(GetLastError(), get_system_category());
TORRENT_ASSERT(ec);
return false;
}
@ -1572,7 +1580,7 @@ namespace libtorrent
}
#endif // F_PREALLOCATE
#if defined TORRENT_LINUX || defined TORRENT_HAS_FALLOCATE
#if defined TORRENT_LINUX || TORRENT_HAS_FALLOCATE
int ret;
#endif

View File

@ -235,7 +235,8 @@ namespace libtorrent
f.file_index = file_iter - begin();
f.offset = file_offset + file_base(*file_iter);
f.size = (std::min)(file_iter->size - file_offset, (size_type)size);
size -= f.size;
TORRENT_ASSERT(f.size <= size);
size -= int(f.size);
file_offset += f.size;
ret.push_back(f);
}

View File

@ -549,8 +549,10 @@ void http_connection::callback(error_code e, char const* data, int size)
for (std::vector<std::pair<size_type, size_type> >::const_iterator i = chunks.begin()
, end(chunks.end()); i != end; ++i)
{
int len = i->second - i->first;
if (i->first - offset + len > size) len = size - i->first + offset;
TORRENT_ASSERT(i->first < INT_MAX);
TORRENT_ASSERT(i->second < INT_MAX);
int len = int(i->second - i->first);
if (i->first - offset + len > size) len = size - int(i->first) + offset;
memmove(write_ptr, data + i->first - offset, len);
write_ptr += len;
}

View File

@ -180,7 +180,9 @@ restart_response:
// if this is a request (not a response)
// we're done once we reach the end of the headers
// if (!m_method.empty()) m_finished = true;
m_body_start_pos = m_recv_pos;
// the HTTP header should always be < 2 GB
TORRENT_ASSERT(m_recv_pos < INT_MAX);
m_body_start_pos = int(m_recv_pos);
break;
}
@ -250,12 +252,13 @@ restart_response:
while (m_cur_chunk_end <= m_recv_pos + incoming && !m_finished && incoming > 0)
{
int payload = m_cur_chunk_end - m_recv_pos;
size_type payload = m_cur_chunk_end - m_recv_pos;
if (payload > 0)
{
TORRENT_ASSERT(payload < INT_MAX);
m_recv_pos += payload;
boost::get<0>(ret) += payload;
incoming -= payload;
boost::get<0>(ret) += int(payload);
incoming -= int(payload);
}
buffer::const_interval buf(recv_buffer.begin + m_cur_chunk_end, recv_buffer.end);
size_type chunk_size;
@ -264,7 +267,7 @@ restart_response:
{
if (chunk_size > 0)
{
std::pair<int, int> chunk_range(m_cur_chunk_end + header_size
std::pair<size_type, size_type> chunk_range(m_cur_chunk_end + header_size
, m_cur_chunk_end + header_size + chunk_size);
m_chunked_ranges.push_back(chunk_range);
}
@ -308,10 +311,13 @@ restart_response:
}
else
{
int payload_received = m_recv_pos - m_body_start_pos + incoming;
size_type payload_received = m_recv_pos - m_body_start_pos + incoming;
if (payload_received > m_content_length
&& m_content_length >= 0)
incoming = m_content_length - m_recv_pos + m_body_start_pos;
{
TORRENT_ASSERT(m_content_length - m_recv_pos + m_body_start_pos < INT_MAX);
incoming = int(m_content_length - m_recv_pos + m_body_start_pos);
}
TORRENT_ASSERT(incoming >= 0);
m_recv_pos += incoming;

View File

@ -380,22 +380,23 @@ namespace libtorrent
m_partial_chunk_header = 0;
TORRENT_ASSERT(chunk_size != 0 || chunk_start.left() <= header_size || chunk_start.begin[header_size] == 'H');
// cut out the chunk header from the receive buffer
cut_receive_buffer(header_size, t->block_size() + 1024, m_chunk_pos + m_body_start);
TORRENT_ASSERT(m_chunk_pos + m_body_start < INT_MAX);
cut_receive_buffer(header_size, t->block_size() + 1024, int(m_chunk_pos + m_body_start));
recv_buffer = receive_buffer();
recv_buffer.begin += m_body_start;
m_chunk_pos += chunk_size;
if (chunk_size == 0)
{
TORRENT_ASSERT(receive_buffer().left() < m_chunk_pos + m_body_start + 1
|| receive_buffer()[m_chunk_pos + m_body_start] == 'H'
|| (m_parser.chunked_encoding() && receive_buffer()[m_chunk_pos + m_body_start] == '\r'));
|| receive_buffer()[int(m_chunk_pos + m_body_start)] == 'H'
|| (m_parser.chunked_encoding() && receive_buffer()[int(m_chunk_pos + m_body_start)] == '\r'));
m_chunk_pos = -1;
}
}
}
int payload = bytes_transferred;
if (payload > m_response_left) payload = m_response_left;
if (payload > m_response_left) payload = int(m_response_left);
if (payload > front_request.length) payload = front_request.length;
m_statistics.received_bytes(payload, 0);
incoming_piece_fragment(payload);

View File

@ -379,8 +379,8 @@ namespace libtorrent
boost::shared_ptr<request_callback> cb = requester();
if (!cb) return;
int interval = e.dict_find_int_value("interval", 1800);
int min_interval = e.dict_find_int_value("min interval", 60);
int interval = int(e.dict_find_int_value("interval", 1800));
int min_interval = int(e.dict_find_int_value("min interval", 60));
std::string trackerid;
lazy_entry const* tracker_id = e.dict_find_string("tracker id");
@ -420,10 +420,10 @@ namespace libtorrent
, interval, min_interval);
return;
}
int complete = scrape_data->dict_find_int_value("complete", -1);
int incomplete = scrape_data->dict_find_int_value("incomplete", -1);
int downloaded = scrape_data->dict_find_int_value("downloaded", -1);
int downloaders = scrape_data->dict_find_int_value("downloaders", -1);
int complete = int(scrape_data->dict_find_int_value("complete", -1));
int incomplete = int(scrape_data->dict_find_int_value("incomplete", -1));
int downloaded = int(scrape_data->dict_find_int_value("downloaded", -1));
int downloaders = int(scrape_data->dict_find_int_value("downloaders", -1));
cb->tracker_scrape_response(tracker_req(), complete
, incomplete, downloaded, downloaders);
return;
@ -514,8 +514,8 @@ namespace libtorrent
#endif
}
int complete = e.dict_find_int_value("complete", -1);
int incomplete = e.dict_find_int_value("incomplete", -1);
int complete = int(e.dict_find_int_value("complete", -1));
int incomplete = int(e.dict_find_int_value("incomplete", -1));
std::list<address> ip_list;
if (m_tracker_connection)

View File

@ -64,12 +64,13 @@ namespace libtorrent
"key not found"
};
if (ev < 0 || ev > i2p_error::num_errors) return "unknown error";
if (ev < 0 || ev >= i2p_error::num_errors) return "unknown error";
return messages[ev];
}
i2p_connection::i2p_connection(io_service& ios)
: m_io_service(ios)
: m_state(sam_idle)
, m_io_service(ios)
{}
i2p_connection::~i2p_connection()
@ -325,7 +326,7 @@ namespace libtorrent
}
else if (strcmp("VERSION", name) == 0)
{
version = atof(ptr);
version = float(atof(ptr));
}
else if (strcmp("VALUE", name) == 0)
{

View File

@ -678,7 +678,7 @@ bool verify_message(lazy_entry const* msg, key_desc_t const desc[], lazy_entry c
if (ret[i])
{
++stack_ptr;
TORRENT_ASSERT(stack_ptr < sizeof(stack)/sizeof(stack[0]));
TORRENT_ASSERT(stack_ptr < int(sizeof(stack)/sizeof(stack[0])));
msg = ret[i];
stack[stack_ptr] = msg;
}
@ -778,11 +778,12 @@ void node_impl::incoming_request(msg const& m, entry& e)
m_table.find_node(info_hash, n, 0);
write_nodes_entry(reply, n);
int prefix = msg_keys[1] ? msg_keys[1]->int_value() : 20;
int prefix = msg_keys[1] ? int(msg_keys[1]->int_value()) : 20;
if (prefix > 20) prefix = 20;
else if (prefix < 4) prefix = 4;
bool ret = lookup_peers(info_hash, prefix, reply);
(void)ret;
#ifdef TORRENT_DHT_VERBOSE_LOGGING
if (ret) TORRENT_LOG(node) << " values: " << reply["values"].list().size();
#endif
@ -829,7 +830,7 @@ void node_impl::incoming_request(msg const& m, entry& e)
return;
}
int port = msg_keys[1]->int_value();
int port = int(msg_keys[1]->int_value());
if (port < 0 || port >= 65536)
{
#ifdef TORRENT_DHT_VERBOSE_LOGGING
@ -859,7 +860,7 @@ void node_impl::incoming_request(msg const& m, entry& e)
// the table get a chance to add it.
m_table.node_seen(id, m.addr);
if (!m_map.empty() && m_map.size() >= m_settings.max_torrents)
if (!m_map.empty() && int(m_map.size()) >= m_settings.max_torrents)
{
// we need to remove some. Remove the ones with the
// fewest peers
@ -868,7 +869,7 @@ void node_impl::incoming_request(msg const& m, entry& e)
for (table_t::iterator i = m_map.begin()
, end(m_map.end()); i != end; ++i)
{
if (i->second.peers.size() > num_peers) continue;
if (int(i->second.peers.size()) > num_peers) continue;
if (i->first == info_hash) continue;
num_peers = i->second.peers.size();
candidate = i;
@ -1016,7 +1017,7 @@ void node_impl::incoming_request(msg const& m, entry& e)
if (i == m_feeds.end())
{
// make sure we don't add too many items
if (m_feeds.size() >= m_settings.max_feed_items)
if (int(m_feeds.size()) >= m_settings.max_feed_items)
{
// delete the least important one (i.e. the one
// the fewest peers are announcing)

View File

@ -95,7 +95,7 @@ int distance_exp(node_id const& n1, node_id const& n2)
return 0;
}
struct static_ { static_() { std::srand(std::time(0)); } } static__;
struct static_ { static_() { std::srand((unsigned int)std::time(0)); } } static__;
// verifies whether a node-id matches the IP it's used from
// returns true if the node-id is OK coming from this source

View File

@ -270,7 +270,7 @@ routing_table::table_t::iterator routing_table::find_bucket(node_id const& id)
}
int bucket_index = (std::min)(159 - distance_exp(m_id, id), num_buckets - 1);
TORRENT_ASSERT(bucket_index < m_buckets.size());
TORRENT_ASSERT(bucket_index < int(m_buckets.size()));
TORRENT_ASSERT(bucket_index >= 0);
table_t::iterator i = m_buckets.begin();
@ -461,7 +461,7 @@ bool routing_table::add_node(node_entry const& e)
// we will only insert it if there is room
// for it, or if some of our nodes have gone
// offline
if (b.size() < m_bucket_size)
if (int(b.size()) < m_bucket_size)
{
if (b.empty()) b.reserve(m_bucket_size);
b.push_back(e);
@ -596,7 +596,7 @@ bool routing_table::add_node(node_entry const& e)
{
if (distance_exp(m_id, j->id) >= 159 - bucket_index)
{
if (b.size() >= m_bucket_size)
if (int(b.size()) >= m_bucket_size)
{
++j;
continue;
@ -606,7 +606,7 @@ bool routing_table::add_node(node_entry const& e)
else
{
// this entry belongs in the new bucket
if (new_bucket.size() < m_bucket_size)
if (int(new_bucket.size()) < m_bucket_size)
new_bucket.push_back(*j);
else
new_replacement_bucket.push_back(*j);
@ -618,12 +618,12 @@ bool routing_table::add_node(node_entry const& e)
// now insert the new node in the appropriate bucket
if (distance_exp(m_id, e.id) >= 159 - bucket_index)
{
if (b.size() < m_bucket_size)
if (int(b.size()) < m_bucket_size)
{
b.push_back(e);
added = true;
}
else if (rb.size() < m_bucket_size)
else if (int(rb.size()) < m_bucket_size)
{
rb.push_back(e);
added = true;
@ -631,12 +631,12 @@ bool routing_table::add_node(node_entry const& e)
}
else
{
if (new_bucket.size() < m_bucket_size)
if (int(new_bucket.size()) < m_bucket_size)
{
new_bucket.push_back(e);
added = true;
}
else if (new_replacement_bucket.size() < m_bucket_size)
else if (int(new_replacement_bucket.size()) < m_bucket_size)
{
new_replacement_bucket.push_back(e);
added = true;
@ -822,7 +822,7 @@ void routing_table::find_node(node_id const& target
table_t::iterator j = i;
++j;
for (; j != m_buckets.end() && l.size() < count; ++j)
for (; j != m_buckets.end() && int(l.size()) < count; ++j)
{
bucket_t& b = j->live_nodes;
size_t to_copy = (std::min)(count - l.size(), b.size());
@ -863,7 +863,7 @@ void routing_table::find_node(node_id const& target
, to_copy, boost::bind(&node_entry::confirmed, _1));
}
}
while (j != m_buckets.begin() && l.size() < count);
while (j != m_buckets.begin() && int(l.size()) < count);
}
/*
routing_table::iterator routing_table::begin() const

View File

@ -67,15 +67,15 @@ TORRENT_DEFINE_LOG(rpc)
void intrusive_ptr_add_ref(observer const* o)
{
TORRENT_ASSERT(o->m_refs >= 0);
TORRENT_ASSERT(o != 0);
TORRENT_ASSERT(o->m_refs >= 0);
++o->m_refs;
}
void intrusive_ptr_release(observer const* o)
{
TORRENT_ASSERT(o->m_refs > 0);
TORRENT_ASSERT(o != 0);
TORRENT_ASSERT(o->m_refs > 0);
if (--o->m_refs == 0)
{
boost::intrusive_ptr<traversal_algorithm> ta = o->m_algorithm;

View File

@ -59,7 +59,7 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent {
struct peer_connection;
class peer_connection;
namespace
{

View File

@ -170,7 +170,7 @@ namespace libtorrent { namespace
lazy_entry const* messages = h.dict_find("m");
if (!messages || messages->type() != lazy_entry::dict_t) return false;
int index = messages->dict_find_int_value("lt_tex", -1);
int index = int(messages->dict_find_int_value("lt_tex", -1));
if (index == -1) return false;
m_message_index = index;

View File

@ -268,7 +268,7 @@ namespace libtorrent { namespace
lazy_entry const* messages = h.dict_find("m");
if (!messages || messages->type() != lazy_entry::dict_t) return false;
int index = messages->dict_find_int_value("LT_metadata", -1);
int index = int(messages->dict_find_int_value("LT_metadata", -1));
if (index == -1) return false;
m_message_index = index;
return true;
@ -538,7 +538,6 @@ namespace libtorrent { namespace
if (pc->type() != peer_connection::bittorrent_connection)
return boost::shared_ptr<peer_plugin>();
bt_peer_connection* c = static_cast<bt_peer_connection*>(pc);
return boost::shared_ptr<peer_plugin>(new metadata_peer_plugin(m_torrent, *pc, *this));
}
@ -546,7 +545,6 @@ namespace libtorrent { namespace
{
// the number of blocks to request
int num_blocks = 256 / 4;
if (num_blocks < 1) num_blocks = 1;
TORRENT_ASSERT(num_blocks <= 128);
int min_element = (std::numeric_limits<int>::max)();

View File

@ -52,11 +52,11 @@ namespace libtorrent {
void packet_buffer::check_invariant() const
{
int count = 0;
for (int i = 0; i < m_capacity; ++i)
for (int i = 0; i < int(m_capacity); ++i)
{
count += m_storage[i] ? 1 : 0;
}
TORRENT_ASSERT(count == m_size);
TORRENT_ASSERT(count == int(m_size));
}
#endif

View File

@ -312,7 +312,6 @@ void rc4_init(const unsigned char* in, unsigned long len, rc4 *state)
unsigned char key[256], tmp, *s;
int keylen, x, y, j;
TORRENT_ASSERT(key != 0);
TORRENT_ASSERT(state != 0);
TORRENT_ASSERT(len <= 256);

View File

@ -952,8 +952,8 @@ namespace libtorrent
| piece_picker::prioritize_partials;
// only one of rarest_first, common_first and sequential can be set.
TORRENT_ASSERT(bool(ret & piece_picker::rarest_first)
+ bool(ret & piece_picker::sequential) <= 1);
TORRENT_ASSERT((ret & piece_picker::rarest_first) ? 1 : 0
+ (ret & piece_picker::sequential) ? 1 : 0 <= 1);
return ret;
}
@ -1307,8 +1307,8 @@ namespace libtorrent
bool match_request(peer_request const& r, piece_block const& b, int block_size)
{
if (b.piece_index != r.piece) return false;
if (b.block_index != r.start / block_size) return false;
if (int(b.piece_index) != r.piece) return false;
if (int(b.block_index) != r.start / block_size) return false;
if (r.start % block_size != 0) return false;
return true;
}
@ -2789,9 +2789,9 @@ namespace libtorrent
TORRENT_ASSERT(!m_disconnecting);
TORRENT_ASSERT(t->valid_metadata());
TORRENT_ASSERT(block.piece_index >= 0);
TORRENT_ASSERT(block.piece_index < t->torrent_file().num_pieces());
TORRENT_ASSERT(int(block.piece_index) < t->torrent_file().num_pieces());
TORRENT_ASSERT(block.block_index >= 0);
TORRENT_ASSERT(block.block_index < t->torrent_file().piece_size(block.piece_index));
TORRENT_ASSERT(int(block.block_index) < t->torrent_file().piece_size(block.piece_index));
TORRENT_ASSERT(!t->picker().is_requested(block) || (t->picker().num_peers(block) > 0));
TORRENT_ASSERT(!t->have_piece(block.piece_index));
TORRENT_ASSERT(std::find_if(m_download_queue.begin(), m_download_queue.end()
@ -2849,7 +2849,7 @@ namespace libtorrent
}
pending_block pb(block);
pb.busy = flags & req_busy;
pb.busy = (flags & req_busy) ? true : false;
if (flags & req_time_critical)
{
m_request_queue.insert(m_request_queue.begin() + m_queued_time_critical
@ -2928,9 +2928,9 @@ namespace libtorrent
TORRENT_ASSERT(t->valid_metadata());
TORRENT_ASSERT(block.piece_index >= 0);
TORRENT_ASSERT(block.piece_index < t->torrent_file().num_pieces());
TORRENT_ASSERT(int(block.piece_index) < t->torrent_file().num_pieces());
TORRENT_ASSERT(block.block_index >= 0);
TORRENT_ASSERT(block.block_index < t->torrent_file().piece_size(block.piece_index));
TORRENT_ASSERT(int(block.block_index) < t->torrent_file().piece_size(block.piece_index));
// if all the peers that requested this block has been
// cancelled, then just ignore the cancel.
@ -4110,8 +4110,9 @@ namespace libtorrent
if (t->ratio() != 1.f)
soon_downloaded = size_type(soon_downloaded * t->ratio());
int upload_speed_limit = (soon_downloaded - have_uploaded
+ bias) / break_even_time;
TORRENT_ASSERT((soon_downloaded - have_uploaded + bias) / break_even_time < INT_MAX);
int upload_speed_limit = int((soon_downloaded - have_uploaded
+ bias) / break_even_time);
if (m_upload_limit > 0 && m_upload_limit < upload_speed_limit)
upload_speed_limit = m_upload_limit;
@ -4495,7 +4496,7 @@ namespace libtorrent
{
if (!m_ignore_bandwidth_limits)
{
bool utp = m_socket->get<utp_stream>();
bool utp = m_socket->get<utp_stream>() != 0;
// in this case, we have data to send, but no
// bandwidth. So, we simply request bandwidth
@ -4621,7 +4622,7 @@ namespace libtorrent
{
if (!m_ignore_bandwidth_limits)
{
bool utp = m_socket->get<utp_stream>();
bool utp = m_socket->get<utp_stream>() != 0;
// in this case, we have outstanding data to
// receive, but no bandwidth quota. So, we simply
@ -5520,6 +5521,8 @@ namespace libtorrent
int count = pc.num_peers;
int count_with_timeouts = pc.num_peers_with_timeouts;
int count_with_nowant = pc.num_peers_with_nowant;
(void)count_with_timeouts;
(void)count_with_nowant;
int picker_count = t->picker().num_peers(b);
if (!t->picker().is_downloaded(b))
TORRENT_ASSERT(picker_count == count);

View File

@ -211,7 +211,7 @@ namespace libtorrent
, end(picked.end()); i != end; ++i)
{
TORRENT_ASSERT(i->piece_index >= 0);
TORRENT_ASSERT(i->piece_index < int(bits.size()));
TORRENT_ASSERT(i->piece_index < bits.size());
TORRENT_ASSERT(bits[i->piece_index]);
TORRENT_ASSERT(!m_piece_map[i->piece_index].have());
}
@ -1365,8 +1365,8 @@ namespace libtorrent
if (options & ignore_whole_pieces) prefer_whole_pieces = 0;
// only one of rarest_first and sequential can be set.
TORRENT_ASSERT(bool(options & rarest_first)
+ bool(options & sequential) <= 1);
TORRENT_ASSERT(((options & rarest_first) ? 1 : 0)
+ ((options & sequential) ? 1 : 0) <= 1);
#ifdef TORRENT_EXPENSIVE_INVARIANT_CHECKS
TORRENT_PIECE_PICKER_INVARIANT_CHECK;
#endif
@ -1963,7 +1963,7 @@ namespace libtorrent
{
TORRENT_ASSERT(block.piece_index >= 0);
TORRENT_ASSERT(block.block_index >= 0);
TORRENT_ASSERT(block.piece_index < (int)m_piece_map.size());
TORRENT_ASSERT(block.piece_index < m_piece_map.size());
if (m_piece_map[block.piece_index].downloading == 0) return false;
std::vector<downloading_piece>::const_iterator i
@ -1980,7 +1980,7 @@ namespace libtorrent
{
TORRENT_ASSERT(block.piece_index >= 0);
TORRENT_ASSERT(block.block_index >= 0);
TORRENT_ASSERT(block.piece_index < (int)m_piece_map.size());
TORRENT_ASSERT(block.piece_index < m_piece_map.size());
if (m_piece_map[block.piece_index].index == piece_pos::we_have_index) return true;
if (m_piece_map[block.piece_index].downloading == 0) return false;
@ -1995,7 +1995,7 @@ namespace libtorrent
{
TORRENT_ASSERT(block.piece_index >= 0);
TORRENT_ASSERT(block.block_index >= 0);
TORRENT_ASSERT(block.piece_index < (int)m_piece_map.size());
TORRENT_ASSERT(block.piece_index < m_piece_map.size());
if (m_piece_map[block.piece_index].index == piece_pos::we_have_index) return true;
if (m_piece_map[block.piece_index].downloading == 0) return false;
@ -2011,8 +2011,8 @@ namespace libtorrent
TORRENT_ASSERT(state != piece_picker::none);
TORRENT_ASSERT(block.piece_index >= 0);
TORRENT_ASSERT(block.block_index >= 0);
TORRENT_ASSERT(block.piece_index < (int)m_piece_map.size());
TORRENT_ASSERT(block.block_index < blocks_in_piece(block.piece_index));
TORRENT_ASSERT(block.piece_index < m_piece_map.size());
TORRENT_ASSERT(int(block.block_index) < blocks_in_piece(block.piece_index));
TORRENT_ASSERT(!m_piece_map[block.piece_index].have());
piece_pos& p = m_piece_map[block.piece_index];
@ -2068,8 +2068,8 @@ namespace libtorrent
{
TORRENT_ASSERT(block.piece_index >= 0);
TORRENT_ASSERT(block.block_index >= 0);
TORRENT_ASSERT(block.piece_index < (int)m_piece_map.size());
TORRENT_ASSERT(block.block_index < blocks_in_piece(block.piece_index));
TORRENT_ASSERT(block.piece_index < m_piece_map.size());
TORRENT_ASSERT(int(block.block_index) < blocks_in_piece(block.piece_index));
piece_pos const& p = m_piece_map[block.piece_index];
if (!p.downloading) return 0;
@ -2102,8 +2102,8 @@ namespace libtorrent
TORRENT_ASSERT(block.piece_index >= 0);
TORRENT_ASSERT(block.block_index >= 0);
TORRENT_ASSERT(block.piece_index < (int)m_piece_map.size());
TORRENT_ASSERT(block.block_index < blocks_in_piece(block.piece_index));
TORRENT_ASSERT(block.piece_index < m_piece_map.size());
TORRENT_ASSERT(int(block.block_index) < blocks_in_piece(block.piece_index));
piece_pos& p = m_piece_map[block.piece_index];
if (p.downloading == 0)
@ -2208,8 +2208,8 @@ namespace libtorrent
{
TORRENT_ASSERT(block.piece_index >= 0);
TORRENT_ASSERT(block.block_index >= 0);
TORRENT_ASSERT(block.piece_index < (int)m_piece_map.size());
TORRENT_ASSERT(block.block_index < blocks_in_piece(block.piece_index));
TORRENT_ASSERT(block.piece_index < m_piece_map.size());
TORRENT_ASSERT(int(block.block_index) < blocks_in_piece(block.piece_index));
piece_pos& p = m_piece_map[block.piece_index];
@ -2317,8 +2317,8 @@ namespace libtorrent
TORRENT_ASSERT(block.piece_index >= 0);
TORRENT_ASSERT(block.block_index >= 0);
TORRENT_ASSERT(block.piece_index < (int)m_piece_map.size());
TORRENT_ASSERT(block.block_index < blocks_in_piece(block.piece_index));
TORRENT_ASSERT(block.piece_index < m_piece_map.size());
TORRENT_ASSERT(int(block.block_index) < blocks_in_piece(block.piece_index));
if (m_piece_map[block.piece_index].downloading == 0)
{
@ -2346,7 +2346,7 @@ namespace libtorrent
if (info.num_peers > 0) --info.num_peers;
if (info.peer == peer) info.peer = 0;
TORRENT_ASSERT(block.block_index < blocks_in_piece(block.piece_index));
TORRENT_ASSERT(int(block.block_index) < blocks_in_piece(block.piece_index));
// if there are other peers, leave the block requested
if (info.num_peers > 0) return;

View File

@ -551,7 +551,7 @@ namespace libtorrent
|| p.banned
|| !p.connectable
|| (p.seed && finished)
|| p.failcount >= m_torrent->settings().max_failcount)
|| int(p.failcount) >= m_torrent->settings().max_failcount)
return false;
aux::session_impl const& ses = m_torrent->session();
@ -1572,6 +1572,9 @@ namespace libtorrent
, supports_utp(true) // assume peers support utp
, confirmed_supports_utp(false)
, supports_holepunch(false)
#ifdef TORRENT_DEBUG
, in_use(false)
#endif
{
TORRENT_ASSERT((src & 0xff) == src);
}

View File

@ -520,8 +520,10 @@ void feed::get_feed_status(feed_status* ret) const
int feed::next_update(time_t now) const
{
if (m_last_update == 0) return INT_MAX;
int ttl = m_ttl == -1 ? m_settings.default_ttl : m_ttl;
return (m_last_update + ttl * 60) - now;
TORRENT_ASSERT((m_last_update + ttl * 60) - now < INT_MAX);
return int((m_last_update + ttl * 60) - now);
}
// defined in session.cpp

View File

@ -85,6 +85,15 @@ void stop_malloc_debug();
namespace libtorrent
{
#ifdef _MSC_VER
namespace aux
{
eh_initializer::eh_initializer()
{
::_set_se_translator(straight_to_debugger);
}
}
#endif
TORRENT_EXPORT void TORRENT_LINK_TEST_NAME() {}
@ -472,7 +481,8 @@ namespace libtorrent
bencode(std::back_inserter(buf), ses_state);
lazy_entry e;
error_code ec;
lazy_bdecode(&buf[0], &buf[0] + buf.size(), e, ec);
int ret = lazy_bdecode(&buf[0], &buf[0] + buf.size(), e, ec);
TORRENT_ASSERT(ret == 0);
TORRENT_SYNC_CALL1(load_state, &e);
}
@ -661,7 +671,7 @@ namespace libtorrent
{
error_code ec;
TORRENT_SYNC_CALL4(listen_on, port_range, boost::ref(ec), net_interface, flags);
return bool(ec);
return !!ec;
}
#endif

View File

@ -196,7 +196,7 @@ namespace aux {
{
seed_random_generator()
{
std::srand(total_microseconds(time_now_hires() - min_time()));
std::srand((unsigned int)total_microseconds(time_now_hires() - min_time()));
}
};
@ -2563,8 +2563,8 @@ namespace aux {
if (m_upload_channel.throttle()) upload_rate = m_upload_channel.throttle();
if (m_download_channel.throttle()) download_rate = m_download_channel.throttle();
m_tcp_upload_channel.throttle(upload_rate * num_tcp_peers / num_peers);
m_tcp_download_channel.throttle(download_rate * num_tcp_peers / num_peers);
m_tcp_upload_channel.throttle(int(upload_rate * num_tcp_peers / num_peers));
m_tcp_download_channel.throttle(int(download_rate * num_tcp_peers / num_peers));
}
}
break;
@ -3600,8 +3600,8 @@ namespace aux {
, end(peers.end()); i != end; ++i)
{
peer_connection const& p = **i;
int rate = p.uploaded_since_unchoke()
* 1000 / total_milliseconds(unchoke_interval);
int rate = int(p.uploaded_since_unchoke()
* 1000 / total_milliseconds(unchoke_interval));
if (rate < rate_threshold) break;

View File

@ -66,12 +66,12 @@ namespace libtorrent
size_type val = key->int_value();
switch (m[i].type)
{
case character: *((char*)dest) = val; break;
case integer: *((int*)dest) = val; break;
case size_integer: *((size_type*)dest) = val; break;
case time_integer: *((time_t*)dest) = val; break;
case character: *((char*)dest) = char(val); break;
case integer: *((int*)dest) = int(val); break;
case size_integer: *((size_type*)dest) = size_type(val); break;
case time_integer: *((time_t*)dest) = time_t(val); break;
case floating_point: *((float*)dest) = float(val) / 1000.f; break;
case boolean: *((bool*)dest) = val; break;
case boolean: *((bool*)dest) = (val != 0); break;
}
}
}

View File

@ -62,7 +62,7 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent {
struct torrent;
class torrent;
namespace
{
@ -85,7 +85,7 @@ namespace
// CRCs from the time it failed and ban the peers that
// sent bad blocks
std::map<piece_block, block_entry>::iterator i = m_block_hashes.lower_bound(piece_block(p, 0));
if (i == m_block_hashes.end() || i->first.piece_index != p) return;
if (i == m_block_hashes.end() || int(i->first.piece_index) != p) return;
int size = m_torrent.torrent_file().piece_size(p);
peer_request r = {p, 0, (std::min)(16*1024, size)};
@ -103,7 +103,7 @@ namespace
TORRENT_ASSERT(i->first.block_index > pb.block_index);
}
if (i == m_block_hashes.end() || i->first.piece_index != p)
if (i == m_block_hashes.end() || int(i->first.piece_index) != p)
break;
r.start += 16*1024;
@ -115,7 +115,7 @@ namespace
#ifndef NDEBUG
// make sure we actually removed all the entries for piece 'p'
i = m_block_hashes.lower_bound(piece_block(p, 0));
TORRENT_ASSERT(i == m_block_hashes.end() || i->first.piece_index != p);
TORRENT_ASSERT(i == m_block_hashes.end() || int(i->first.piece_index) != p);
#endif
if (m_torrent.is_seed())

View File

@ -63,7 +63,7 @@ namespace libtorrent
"SOCKS identd could not identify username"
};
if (ev < 0 || ev > socks_error::num_errors) return "unknown error";
if (ev < 0 || ev >= socks_error::num_errors) return "unknown error";
return messages[ev];
}
#endif

View File

@ -722,7 +722,7 @@ namespace libtorrent
if (!file_handle || ec) return slot;
size_type data_start = file_handle->sparse_end(file_offset);
return (data_start + m_files.piece_length() - 1) / m_files.piece_length();
return int((data_start + m_files.piece_length() - 1) / m_files.piece_length());
}
bool storage::verify_resume_data(lazy_entry const& rd, error_code& error)
@ -748,7 +748,7 @@ namespace libtorrent
{
m_file_priority.resize(file_priority->list_size());
for (int i = 0; i < file_priority->list_size(); ++i)
m_file_priority[i] = file_priority->list_int_value_at(i, 1);
m_file_priority[i] = boost::uint8_t(file_priority->list_int_value_at(i, 1));
}
std::vector<std::pair<size_type, std::time_t> > file_sizes;
@ -1240,7 +1240,7 @@ ret:
&& ((adjusted_offset & (file_handle->pos_alignment()-1)) != 0
|| (uintptr_t(tmp_bufs->iov_base) & (file_handle->buf_alignment()-1)) != 0))
{
bytes_transferred = (this->*op.unaligned_op)(file_handle, adjusted_offset
bytes_transferred = (int)(this->*op.unaligned_op)(file_handle, adjusted_offset
, tmp_bufs, num_tmp_bufs, ec);
}
else
@ -1281,7 +1281,8 @@ ret:
const int size = bufs_size(bufs, num_bufs);
const int start_adjust = file_offset & pos_align;
const int aligned_start = file_offset - start_adjust;
TORRENT_ASSERT(start_adjust == (file_offset % file_handle->pos_alignment()));
const size_type aligned_start = file_offset - start_adjust;
const int aligned_size = ((size+start_adjust) & size_align)
? ((size+start_adjust) & ~size_align) + size_align + 1 : size + start_adjust;
const int num_blocks = (aligned_size + block_size - 1) / block_size;
@ -2067,7 +2068,7 @@ ret:
}
int block_size = (std::min)(16 * 1024, m_files.piece_length());
int blocks_per_piece = rd.dict_find_int_value("blocks per piece", -1);
int blocks_per_piece = int(rd.dict_find_int_value("blocks per piece", -1));
if (blocks_per_piece != -1
&& blocks_per_piece != m_files.piece_length() / block_size)
{

View File

@ -138,7 +138,7 @@ namespace libtorrent
mach_timebase_info(&timebase_info);
boost::uint64_t at = mach_absolute_time();
// make sure we don't overflow
TORRENT_ASSERT((at >= 0 && at >= at / 1000 * timebase_info.numer / timebase_info.denom)
TORRENT_ASSERT((at >= at / 1000 * timebase_info.numer / timebase_info.denom)
|| (at < 0 && at < at / 1000 * timebase_info.numer / timebase_info.denom));
return ptime(at / 1000 * timebase_info.numer / timebase_info.denom);
}

View File

@ -124,12 +124,13 @@ namespace
// returns the amount of free upload left after
// it has been distributed to the peers
size_type distribute_free_upload(
boost::uint32_t distribute_free_upload(
torrent::peer_iterator start
, torrent::peer_iterator end
, size_type free_upload)
{
if (free_upload <= 0) return free_upload;
TORRENT_ASSERT(free_upload >= 0);
if (free_upload <= 0) return 0;
int num_peers = 0;
size_type total_diff = 0;
for (torrent::peer_iterator i = start; i != end; ++i)
@ -141,7 +142,7 @@ namespace
++num_peers;
}
if (num_peers == 0) return free_upload;
if (num_peers == 0) return boost::uint32_t(free_upload);
size_type upload_share;
if (total_diff >= 0)
{
@ -151,7 +152,7 @@ namespace
{
upload_share = (free_upload + total_diff) / num_peers;
}
if (upload_share < 0) return free_upload;
if (upload_share < 0) return boost::uint32_t(free_upload);
for (torrent::peer_iterator i = start; i != end; ++i)
{
@ -160,7 +161,7 @@ namespace
p->add_free_upload(upload_share);
free_upload -= upload_share;
}
return free_upload;
return (std::min)(free_upload, size_type(UINT_MAX));
}
struct find_peer_by_ip
@ -526,7 +527,7 @@ namespace libtorrent
m_torrent_file = tf;
m_ses.m_torrents.insert(std::make_pair(m_torrent_file->info_hash(), shared_from_this()));
TORRENT_ASSERT(num_torrents == m_ses.m_torrents.size());
TORRENT_ASSERT(num_torrents == int(m_ses.m_torrents.size()));
// if the user added any trackers while downloading the
// .torrent file, serge them into the new tracker list
@ -1206,12 +1207,12 @@ namespace libtorrent
piece_block pb(pr.piece, pr.start / block);
for (; pr.length >= block; pr.length -= block, ++pb.block_index)
{
if (pb.block_index == blocks_per_piece) { pb.block_index = 0; ++pb.piece_index; }
if (int(pb.block_index) == blocks_per_piece) { pb.block_index = 0; ++pb.piece_index; }
m_picker->mark_as_finished(pb, 0);
}
// ugly edge case where padfiles are not used they way they're
// supposed to be. i.e. added back-to back or at the end
if (pb.block_index == blocks_per_piece) { pb.block_index = 0; ++pb.piece_index; }
if (int(pb.block_index) == blocks_per_piece) { pb.block_index = 0; ++pb.piece_index; }
if (pr.length > 0 && ((boost::next(i) != end && boost::next(i)->pad_file)
|| boost::next(i) == end))
{
@ -2876,14 +2877,14 @@ namespace libtorrent
, end(dq.end()); k != end; ++k)
{
if (k->timed_out || k->not_wanted) continue;
if (k->block.piece_index != index) continue;
if (int(k->block.piece_index) != index) continue;
m_picker->mark_as_downloading(k->block, p->peer_info_struct()
, (piece_picker::piece_state_t)p->peer_speed());
}
for (std::vector<pending_block>::const_iterator k = rq.begin()
, end(rq.end()); k != end; ++k)
{
if (k->block.piece_index != index) continue;
if (int(k->block.piece_index) != index) continue;
m_picker->mark_as_downloading(k->block, p->peer_info_struct()
, (piece_picker::piece_state_t)p->peer_speed());
}
@ -3480,7 +3481,7 @@ namespace libtorrent
// in the torrent
TORRENT_ASSERT((int)bitmask.size() == m_torrent_file->num_files());
if (bitmask.size() != m_torrent_file->num_files()) return;
if (int(bitmask.size()) != m_torrent_file->num_files()) return;
size_type position = 0;
@ -3670,7 +3671,7 @@ namespace libtorrent
{
TORRENT_ASSERT(p->associated_torrent().lock().get() == this);
TORRENT_ASSERT(p->share_diff() < (std::numeric_limits<size_type>::max)());
m_available_free_upload += p->share_diff();
add_free_upload(p->share_diff());
}
TORRENT_ASSERT(pp->prev_amount_upload == 0);
TORRENT_ASSERT(pp->prev_amount_download == 0);
@ -4824,7 +4825,7 @@ namespace libtorrent
, seconds(timeout));
#ifndef BOOST_NO_EXCEPTIONS
}
catch (std::exception& e)
catch (std::exception&)
{
std::set<peer_connection*>::iterator i
= m_connections.find(boost::get_pointer(c));
@ -4926,7 +4927,7 @@ namespace libtorrent
return false;
}
if (int(m_connections.size()) >= m_max_connections)
if (m_connections.size() >= m_max_connections)
{
p->disconnect(errors::too_many_connections);
return false;
@ -4950,6 +4951,7 @@ namespace libtorrent
}
catch (std::exception& e)
{
(void)e;
#if defined TORRENT_LOGGING
(*m_ses.m_logger) << time_now_string() << " CLOSING CONNECTION "
<< p->remote() << " policy::new_connection threw: " << e.what() << "\n";
@ -4977,7 +4979,7 @@ namespace libtorrent
bool torrent::want_more_peers() const
{
return int(m_connections.size()) < m_max_connections
return m_connections.size() < m_max_connections
&& !is_paused()
&& ((m_state != torrent_status::checking_files
&& m_state != torrent_status::checking_resume_data
@ -5078,7 +5080,7 @@ namespace libtorrent
int num_conns = m_connections.size();
#endif
p->disconnect(ec);
TORRENT_ASSERT(m_connections.size() == num_conns - 1);
TORRENT_ASSERT(int(m_connections.size()) == num_conns - 1);
}
return ret;
@ -5458,7 +5460,7 @@ namespace libtorrent
if (associated_torrent != this && associated_torrent != 0)
TORRENT_ASSERT(false);
}
TORRENT_ASSERT(num_uploads == m_num_uploads);
TORRENT_ASSERT(num_uploads == int(m_num_uploads));
if (has_picker())
{
@ -5657,7 +5659,7 @@ namespace libtorrent
if (limit <= 0) limit = (std::numeric_limits<int>::max)();
m_max_connections = limit;
if (num_peers() > m_max_connections)
if (num_peers() > int(m_max_connections))
{
disconnect_peers(num_peers() - m_max_connections
, error_code(errors::too_many_connections, get_libtorrent_category()));
@ -6100,8 +6102,6 @@ namespace libtorrent
if (m_allow_peers == b
&& m_graceful_pause_mode == graceful) return;
bool checking_files = should_check_files();
m_allow_peers = b;
if (!m_ses.is_paused())
m_graceful_pause_mode = graceful;
@ -6128,7 +6128,6 @@ namespace libtorrent
&& m_announce_to_dht
&& m_announce_to_trackers
&& m_announce_to_lsd) return;
bool checking_files = should_check_files();
m_allow_peers = true;
m_announce_to_dht = true;
m_announce_to_trackers = true;
@ -6337,8 +6336,8 @@ namespace libtorrent
{
// accumulate all the free download we get
// and add it to the available free upload
m_available_free_upload += collect_free_download(
this->begin(), this->end());
add_free_upload(collect_free_download(
this->begin(), this->end()));
// distribute the free upload among the peers
m_available_free_upload = distribute_free_upload(
@ -6351,7 +6350,7 @@ namespace libtorrent
// if we're in upload only mode and we're auto-managed
// leave upload mode every 10 minutes hoping that the error
// condition has been fixed
if (m_upload_mode && m_auto_managed && m_upload_mode_time
if (m_upload_mode && m_auto_managed && int(m_upload_mode_time)
>= settings().optimistic_disk_retry)
{
set_upload_mode(false);
@ -6444,6 +6443,7 @@ namespace libtorrent
}
catch (std::exception& e)
{
(void)e;
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING
(*p->m_logger) << "**ERROR**: " << e.what() << "\n";
#endif
@ -6541,7 +6541,7 @@ namespace libtorrent
// don't have more pieces downloading in parallel than 5% of the total
// number of pieces we have downloaded
if (m_picker->get_download_queue().size() > num_downloaded_pieces / 20)
if (int(m_picker->get_download_queue().size()) > num_downloaded_pieces / 20)
return;
// one more important property is that there are enough pieces
@ -6567,8 +6567,8 @@ namespace libtorrent
}
// don't count pieces we already have or are downloading
if (!pp.filtered() || pp.have()) continue;
if (pp.peer_count > rarest_rarity) continue;
if (pp.peer_count == rarest_rarity)
if (int(pp.peer_count) > rarest_rarity) continue;
if (int(pp.peer_count) == rarest_rarity)
{
rarest_pieces.push_back(i);
continue;
@ -7068,7 +7068,7 @@ namespace libtorrent
if (offset + block > file->offset + file->size)
{
int left_over = block_size() - block;
int left_over = int(block_size() - block);
// split the block on multiple files
while (block > 0)
{
@ -7130,7 +7130,7 @@ namespace libtorrent
TORRENT_ASSERT(!is_finished());
#endif
if (m_state == s) return;
if (int(m_state) == s) return;
if (m_ses.m_alerts.should_post<state_changed_alert>())
m_ses.m_alerts.post_alert(state_changed_alert(get_handle(), s, (torrent_status::state_t)m_state));
m_state = s;

View File

@ -649,6 +649,7 @@ namespace libtorrent
torrent_info::torrent_info(std::string const& filename, error_code& ec, int flags)
: m_piece_hashes(0)
, m_creation_date(0)
, m_merkle_first_leaf(0)
, m_info_section_size(0)
, m_multifile(false)
, m_private(false)
@ -668,6 +669,7 @@ namespace libtorrent
torrent_info::torrent_info(std::wstring const& filename, error_code& ec, int flags)
: m_piece_hashes(0)
, m_creation_date(0)
, m_merkle_first_leaf(0)
, m_info_section_size(0)
, m_multifile(false)
, m_private(false)
@ -694,6 +696,7 @@ namespace libtorrent
: m_piece_hashes(0)
, m_creation_date(time(0))
, m_info_hash(info_hash)
, m_merkle_first_leaf(0)
, m_info_section_size(0)
, m_multifile(false)
, m_private(false)

View File

@ -223,9 +223,11 @@ void udp_socket::maybe_realloc_buffers(int which)
if (no_mem)
{
free(m_v4_buf);
m_v4_buf = 0;
m_v4_buf_size = 0;
#if TORRENT_USE_IPV6
free(m_v6_buf);
m_v6_buf = 0;
m_v6_buf_size = 0;
#endif
if (m_callback) m_callback(error::no_memory, m_v4_ep, 0, 0);
@ -313,6 +315,7 @@ void udp_socket::on_read(udp::socket* s, error_code const& e, std::size_t bytes_
if (s == &m_ipv6_sock && num_outstanding() == 0)
{
maybe_realloc_buffers(2);
if (m_abort) return;
++m_v6_outstanding;
s->async_receive_from(asio::buffer(m_v6_buf, m_v6_buf_size)
, m_v6_ep, boost::bind(&udp_socket::on_read, this, s, _1, _2));
@ -322,6 +325,7 @@ void udp_socket::on_read(udp::socket* s, error_code const& e, std::size_t bytes_
if (m_v4_outstanding == 0)
{
maybe_realloc_buffers(1);
if (m_abort) return;
++m_v4_outstanding;
s->async_receive_from(asio::buffer(m_v4_buf, m_v4_buf_size)
, m_v4_ep, boost::bind(&udp_socket::on_read, this, s, _1, _2));
@ -360,6 +364,7 @@ void udp_socket::on_read(udp::socket* s, error_code const& e, std::size_t bytes_
if (num_outstanding() == 0)
{
maybe_realloc_buffers(2);
if (m_abort) return;
#if defined TORRENT_ASIO_DEBUGGING
add_outstanding_async("udp_socket::on_read");
@ -397,6 +402,7 @@ void udp_socket::on_read(udp::socket* s, error_code const& e, std::size_t bytes_
if (m_v4_outstanding == 0)
{
maybe_realloc_buffers(1);
if (m_abort) return;
#if defined TORRENT_ASIO_DEBUGGING
add_outstanding_async("udp_socket::on_read");
@ -597,6 +603,7 @@ void udp_socket::bind(udp::endpoint const& ep, error_code& ec)
if (m_v4_outstanding == 0)
{
maybe_realloc_buffers(1);
if (m_abort) return;
#if defined TORRENT_ASIO_DEBUGGING
add_outstanding_async("udp_socket::on_read");
#endif
@ -616,6 +623,7 @@ void udp_socket::bind(udp::endpoint const& ep, error_code& ec)
if (m_v6_outstanding == 0)
{
maybe_realloc_buffers(2);
if (m_abort) return;
#if defined TORRENT_ASIO_DEBUGGING
add_outstanding_async("udp_socket::on_read");
#endif
@ -648,6 +656,7 @@ void udp_socket::bind(int port)
#endif
maybe_realloc_buffers();
if (m_abort) return;
m_ipv4_sock.open(udp::v4(), ec);
if (!ec)
@ -810,7 +819,7 @@ void udp_socket::on_connected(error_code const& e)
write_uint8(0, p); // no authentication
write_uint8(2, p); // username/password
}
TORRENT_ASSERT_VAL(p - m_tmp_buf < sizeof(m_tmp_buf), (p - m_tmp_buf));
TORRENT_ASSERT_VAL(p - m_tmp_buf < int(sizeof(m_tmp_buf)), (p - m_tmp_buf));
#if defined TORRENT_ASIO_DEBUGGING
add_outstanding_async("udp_socket::on_handshake1");
#endif
@ -873,7 +882,7 @@ void udp_socket::handshake2(error_code const& e)
write_string(m_proxy_settings.username, p);
write_uint8(m_proxy_settings.password.size(), p);
write_string(m_proxy_settings.password, p);
TORRENT_ASSERT_VAL(p - m_tmp_buf < sizeof(m_tmp_buf), (p - m_tmp_buf));
TORRENT_ASSERT_VAL(p - m_tmp_buf < int(sizeof(m_tmp_buf)), (p - m_tmp_buf));
#if defined TORRENT_ASIO_DEBUGGING
add_outstanding_async("udp_socket::on_handshake3");
#endif
@ -951,7 +960,7 @@ void udp_socket::socks_forward_udp()
port = m_ipv6_sock.local_endpoint(ec).port();
#endif
detail::write_uint16(port , p);
TORRENT_ASSERT_VAL(p - m_tmp_buf < sizeof(m_tmp_buf), (p - m_tmp_buf));
TORRENT_ASSERT_VAL(p - m_tmp_buf < int(sizeof(m_tmp_buf)), (p - m_tmp_buf));
#if defined TORRENT_ASIO_DEBUGGING
add_outstanding_async("udp_socket::connect1");
#endif
@ -991,7 +1000,7 @@ void udp_socket::connect2(error_code const& e)
char* p = &m_tmp_buf[0];
int version = read_uint8(p); // VERSION
int status = read_uint8(p); // STATUS
read_uint8(p); // RESERVED
++p; // RESERVED
int atyp = read_uint8(p); // address type
if (version != 5) return;
@ -1113,7 +1122,7 @@ void rate_limited_udp_socket::on_tick(error_code const& e)
while (!m_queue.empty() && int(m_queue.front().buf.size()) <= m_quota)
{
queued_packet const& p = m_queue.front();
TORRENT_ASSERT(m_quota >= p.buf.size());
TORRENT_ASSERT(m_quota >= int(p.buf.size()));
m_quota -= p.buf.size();
error_code ec;
udp_socket::send(p.ep, &p.buf[0], p.buf.size(), ec, p.flags);

View File

@ -401,7 +401,7 @@ void upnp::on_reply(udp::endpoint const& from, char* buffer
for (std::vector<ip_route>::const_iterator i = routes.begin()
, end(routes.end()); i != end; ++i)
{
if (num_chars >= sizeof(msg)-1) break;
if (num_chars >= int(sizeof(msg)-1)) break;
num_chars += snprintf(msg + num_chars, sizeof(msg) - num_chars, "(%s,%s) "
, print_address(i->gateway).c_str(), print_address(i->netmask).c_str());
}
@ -772,7 +772,7 @@ namespace
struct parse_state
{
parse_state(): in_service(false) {}
parse_state(): in_service(false), service_type(0) {}
void reset(char const* st)
{
in_service = false;

View File

@ -507,7 +507,7 @@ namespace libtorrent { namespace
// if we only have one block, and thus requested it from a single
// peer, we bump up the retry time a lot more to try other peers
bool single_peer = m_requested_metadata.size() == 1;
for (int i = 0; i < m_requested_metadata.size(); ++i)
for (int i = 0; i < int(m_requested_metadata.size()); ++i)
{
m_requested_metadata[i].num_requests = 0;
boost::shared_ptr<ut_metadata_peer_plugin> peer

View File

@ -243,7 +243,7 @@ namespace libtorrent { namespace
lazy_entry const* messages = h.dict_find("m");
if (!messages || messages->type() != lazy_entry::dict_t) return false;
int index = messages->dict_find_int_value(extension_name, -1);
int index = int(messages->dict_find_int_value(extension_name, -1));
if (index == -1) return false;
m_message_index = index;
return true;
@ -326,7 +326,7 @@ namespace libtorrent { namespace
tcp::endpoint adr = detail::read_v4_endpoint<tcp::endpoint>(in);
char flags = *fin++;
if (m_peers.size() >= m_torrent.settings().max_pex_peers) break;
if (int(m_peers.size()) >= m_torrent.settings().max_pex_peers) break;
// ignore local addresses unless the peer is local to us
if (is_local(adr.address()) && !is_local(m_pc.remote().address())) continue;
@ -377,7 +377,7 @@ namespace libtorrent { namespace
char flags = *fin++;
// ignore local addresses unless the peer is local to us
if (is_local(adr.address()) && !is_local(m_pc.remote().address())) continue;
if (m_peers6.size() >= m_torrent.settings().max_pex_peers) break;
if (int(m_peers6.size()) >= m_torrent.settings().max_pex_peers) break;
peers6_t::value_type v(adr.address().to_v6().to_bytes(), adr.port());
peers6_t::iterator j = std::lower_bound(m_peers6.begin(), m_peers6.end(), v);
@ -542,7 +542,6 @@ namespace libtorrent { namespace
if (pc->type() != peer_connection::bittorrent_connection)
return boost::shared_ptr<peer_plugin>();
bt_peer_connection* c = static_cast<bt_peer_connection*>(pc);
return boost::shared_ptr<peer_plugin>(new ut_pex_peer_plugin(m_torrent
, *pc, *this));
}

View File

@ -202,7 +202,7 @@ namespace libtorrent
{
// UTP_LOGV("incoming packet size:%d\n", size);
if (size < sizeof(utp_header)) return false;
if (size < int(sizeof(utp_header))) return false;
utp_header const* ph = (utp_header*)p;

View File

@ -243,6 +243,7 @@ struct utp_socket_impl
, m_acked_seq_nr(0)
, m_fast_resend_seq_nr(0)
, m_eof_seq_nr(0)
, m_loss_seq_nr(0)
, m_mtu(TORRENT_ETHERNET_MTU - TORRENT_IPV4_HEADER - TORRENT_UDP_HEADER - 8 - 24 - 36)
, m_mtu_floor(TORRENT_INET_MIN_MTU - TORRENT_IPV4_HEADER - TORRENT_UDP_HEADER)
, m_mtu_ceiling(TORRENT_ETHERNET_MTU - TORRENT_IPV4_HEADER - TORRENT_UDP_HEADER)
@ -906,7 +907,7 @@ size_t utp_stream::read_some(bool clear_buffers)
memcpy(target->buf, p->buf + p->header_size, to_copy);
ret += to_copy;
target->buf = ((char*)target->buf) + to_copy;
TORRENT_ASSERT(target->len >= to_copy);
TORRENT_ASSERT(int(target->len) >= to_copy);
target->len -= to_copy;
m_impl->m_receive_buffer_size -= to_copy;
TORRENT_ASSERT(m_impl->m_read_buffer_size >= to_copy);
@ -1327,7 +1328,7 @@ void utp_socket_impl::parse_sack(boost::uint16_t packet_ack, char const* ptr
packet* p = (packet*)m_outbuf.remove(ack_nr);
if (p)
{
acked_bytes += p->size - p->header_size;
*acked_bytes += p->size - p->header_size;
// each ACKed packet counts as a duplicate ack
UTP_LOGV("%8p: duplicate_acks:%u fast_resend_seq_nr:%u\n"
, this, m_duplicate_acks, m_fast_resend_seq_nr);
@ -1398,6 +1399,8 @@ void utp_socket_impl::write_payload(char* ptr, int size)
{
// i points to the iovec we'll start copying from
int to_copy = (std::min)(size, int(i->len));
TORRENT_ASSERT(to_copy >= 0);
TORRENT_ASSERT(to_copy < INT_MAX / 2 && m_written < INT_MAX / 2);
memcpy(ptr, static_cast<char const*>(i->buf), to_copy);
size -= to_copy;
if (m_written == 0)
@ -1405,8 +1408,6 @@ void utp_socket_impl::write_payload(char* ptr, int size)
m_write_timeout = now + milliseconds(100);
UTP_LOGV("%8p: setting write timeout to 100 ms from now\n", this);
}
TORRENT_ASSERT(to_copy >= 0);
TORRENT_ASSERT(to_copy < INT_MAX / 2 && m_written < INT_MAX / 2);
m_written += to_copy;
ptr += to_copy;
i->len -= to_copy;
@ -2063,7 +2064,7 @@ void utp_socket_impl::init_mtu(int link_mtu, int utp_mtu)
// if the window size is smaller than one packet size
// set it to one
if ((m_cwnd >> 16) < m_mtu) m_cwnd = m_mtu << 16;
if ((m_cwnd >> 16) < m_mtu) m_cwnd = boost::int64_t(m_mtu) << 16;
UTP_LOGV("%8p: intializing MTU to: %d [%d, %d]\n"
, this, m_mtu, m_mtu_floor, m_mtu_ceiling);
@ -2299,8 +2300,8 @@ bool utp_socket_impl::incoming_packet(char const* buf, int size
return true;
}
int next_extension = unsigned(*ptr++);
unsigned int len = unsigned(*ptr++);
if (ptr - buf + len > size)
int len = unsigned(*ptr++);
if (ptr - buf + len > size_t(size))
{
UTP_LOGV("%8p: invalid extension header size:%d packet:%d\n"
, this, len, int(ptr - buf));
@ -2795,7 +2796,7 @@ void utp_socket_impl::tick(ptime const& now)
// we can now sent messages again, the send window was opened
if ((m_cwnd >> 16) < m_mtu) window_opened = true;
m_cwnd = m_mtu << 16;
m_cwnd = boost::int64_t(m_mtu) << 16;
if (m_outbuf.size()) ++m_num_timeouts;
m_timeout = now + milliseconds(packet_timeout());
@ -2912,7 +2913,7 @@ void utp_socket_impl::check_receive_buffers() const
size += p->size - p->header_size;
}
TORRENT_ASSERT(size == m_receive_buffer_size);
TORRENT_ASSERT(int(size) == m_receive_buffer_size);
}
}

View File

@ -119,8 +119,8 @@ namespace libtorrent
// would otherwise point to one past the end
int correction = m_block_pos ? -1 : 0;
ret.block_index = (m_requests.front().start + m_block_pos + correction) / t->block_size();
TORRENT_ASSERT(ret.block_index < piece_block::invalid.block_index);
TORRENT_ASSERT(ret.piece_index < piece_block::invalid.piece_index);
TORRENT_ASSERT(ret.block_index < int(piece_block::invalid.block_index));
TORRENT_ASSERT(ret.piece_index < int(piece_block::invalid.piece_index));
ret.full_block_bytes = t->block_size();
const int last_piece = t->torrent_file().num_pieces() - 1;
@ -292,7 +292,7 @@ namespace libtorrent
{
#ifdef TORRENT_DEBUG
TORRENT_ASSERT(m_statistics.last_payload_downloaded()
+ m_statistics.last_protocol_downloaded() + bytes_transferred
+ m_statistics.last_protocol_downloaded() + int(bytes_transferred)
== dl_target);
#endif
@ -306,7 +306,7 @@ namespace libtorrent
bool error = false;
boost::tie(payload, protocol) = m_parser.incoming(recv_buffer, error);
m_statistics.received_bytes(0, protocol);
TORRENT_ASSERT(bytes_transferred >= protocol);
TORRENT_ASSERT(int(bytes_transferred) >= protocol);
bytes_transferred -= protocol;
if (error)
@ -335,7 +335,7 @@ namespace libtorrent
TORRENT_ASSERT(bytes_transferred == 0);
#ifdef TORRENT_DEBUG
TORRENT_ASSERT(m_statistics.last_payload_downloaded()
+ m_statistics.last_protocol_downloaded() + bytes_transferred
+ m_statistics.last_protocol_downloaded() + int(bytes_transferred)
== dl_target);
#endif
break;
@ -347,7 +347,7 @@ namespace libtorrent
TORRENT_ASSERT(bytes_transferred == 0);
#ifdef TORRENT_DEBUG
TORRENT_ASSERT(m_statistics.last_payload_downloaded()
+ m_statistics.last_protocol_downloaded() + bytes_transferred
+ m_statistics.last_protocol_downloaded() + int(bytes_transferred)
== dl_target);
#endif
break;
@ -547,7 +547,7 @@ namespace libtorrent
bool ret = m_parser.parse_chunk_header(chunk_start, &chunk_size, &header_size);
if (!ret)
{
TORRENT_ASSERT(bytes_transferred >= chunk_start.left() - m_partial_chunk_header);
TORRENT_ASSERT(int(bytes_transferred) >= chunk_start.left() - m_partial_chunk_header);
bytes_transferred -= chunk_start.left() - m_partial_chunk_header;
m_statistics.received_bytes(0, chunk_start.left() - m_partial_chunk_header);
m_partial_chunk_header = chunk_start.left();
@ -559,13 +559,14 @@ namespace libtorrent
#ifdef TORRENT_VERBOSE_LOGGING
peer_log("*** parsed chunk: %d header_size: %d", chunk_size, header_size);
#endif
TORRENT_ASSERT(bytes_transferred >= header_size - m_partial_chunk_header);
TORRENT_ASSERT(int(bytes_transferred) >= header_size - m_partial_chunk_header);
bytes_transferred -= header_size - m_partial_chunk_header;
m_statistics.received_bytes(0, header_size - m_partial_chunk_header);
m_partial_chunk_header = 0;
TORRENT_ASSERT(chunk_size != 0 || chunk_start.left() <= header_size || chunk_start.begin[header_size] == 'H');
// cut out the chunk header from the receive buffer
cut_receive_buffer(header_size, t->block_size() + 1024, m_body_start + m_chunk_pos);
TORRENT_ASSERT(m_body_start + m_chunk_pos < INT_MAX);
cut_receive_buffer(header_size, t->block_size() + 1024, int(m_body_start + m_chunk_pos));
recv_buffer = receive_buffer();
recv_buffer.begin += m_body_start;
m_chunk_pos += chunk_size;
@ -581,8 +582,8 @@ namespace libtorrent
}
}
int left_in_response = range_end - range_start - m_range_pos;
int payload_transferred = (std::min)(left_in_response, int(bytes_transferred));
size_type left_in_response = range_end - range_start - m_range_pos;
int payload_transferred = int((std::min)(left_in_response, size_type(bytes_transferred)));
torrent_info const& info = t->torrent_file();
@ -596,7 +597,7 @@ namespace libtorrent
, front_request.start, front_request.length);
#endif
m_statistics.received_bytes(payload_transferred, 0);
TORRENT_ASSERT(bytes_transferred >= payload_transferred);
TORRENT_ASSERT(int(bytes_transferred) >= payload_transferred);
bytes_transferred -= payload_transferred;
m_range_pos += payload_transferred;
m_block_pos += payload_transferred;

View File

@ -275,7 +275,7 @@ setup_transfer(session* ses1, session* ses2, session* ses3
ses2->set_alert_mask(~(alert::progress_notification | alert::stats_notification));
if (ses3) ses3->set_alert_mask(~(alert::progress_notification | alert::stats_notification));
std::srand(time(0));
std::srand((unsigned int)time(0));
peer_id pid;
std::generate(&pid[0], &pid[0] + 20, std::rand);
ses1->set_peer_id(pid);
@ -831,7 +831,7 @@ void web_server_thread(int* port, bool ssl, bool chunked)
break;
}
offset += p.body_start() + p.content_length();
offset += int(p.body_start() + p.content_length());
// fprintf(stderr, "offset: %d len: %d\n", offset, len);
if (p.method() != "get" && p.method() != "post")