diff --git a/include/libtorrent/bandwidth_limit.hpp b/include/libtorrent/bandwidth_limit.hpp index 1d9ca5608..727f0c8a3 100644 --- a/include/libtorrent/bandwidth_limit.hpp +++ b/include/libtorrent/bandwidth_limit.hpp @@ -49,7 +49,11 @@ struct TORRENT_EXPORT bandwidth_channel // 0 means infinite void throttle(int limit); - int throttle() const { return m_limit; } + int throttle() const + { + TORRENT_ASSERT_VAL(m_limit < INT_MAX, m_limit); + return int(m_limit); + } int quota_left() const; void update_quota(int dt_milliseconds); diff --git a/include/libtorrent/copy_ptr.hpp b/include/libtorrent/copy_ptr.hpp index 3d9a96937..0b2fcadd2 100644 --- a/include/libtorrent/copy_ptr.hpp +++ b/include/libtorrent/copy_ptr.hpp @@ -58,7 +58,7 @@ namespace libtorrent m_ptr = p.m_ptr; p.m_ptr = tmp; } - operator bool() const { return m_ptr; } + operator bool() const { return m_ptr != 0; } ~copy_ptr() { delete m_ptr; } private: T* m_ptr; diff --git a/include/libtorrent/create_torrent.hpp b/include/libtorrent/create_torrent.hpp index e15d4b10a..d0720736d 100644 --- a/include/libtorrent/create_torrent.hpp +++ b/include/libtorrent/create_torrent.hpp @@ -191,7 +191,7 @@ namespace libtorrent if (ec) return; // recurse into directories - bool recurse = s.mode & file_status::directory; + bool recurse = (s.mode & file_status::directory) != 0; // if the file is not a link or we're following links, and it's a directory // only then should we recurse @@ -284,7 +284,7 @@ namespace libtorrent // the number of bytes from this file we just read while (left_in_piece > 0) { - int to_hash_for_file = (std::min)(size_type(left_in_piece), left_in_file); + int to_hash_for_file = int((std::min)(size_type(left_in_piece), left_in_file)); filehash.update(buf.bytes(), to_hash_for_file); left_in_file -= to_hash_for_file; left_in_piece -= to_hash_for_file; diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 41bff841f..5b14f83ba 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -685,7 +685,7 @@ namespace libtorrent void read_resume_data(lazy_entry const& rd); void seen_complete() { m_last_seen_complete = time(0); } - int time_since_complete() const { return time(0) - m_last_seen_complete; } + int time_since_complete() const { return int(time(0) - m_last_seen_complete); } time_t last_seen_complete() const { return m_last_seen_complete; } // LOGGING diff --git a/include/libtorrent/torrent_info.hpp b/include/libtorrent/torrent_info.hpp index fee913e2a..5e54dbf76 100644 --- a/include/libtorrent/torrent_info.hpp +++ b/include/libtorrent/torrent_info.hpp @@ -61,7 +61,7 @@ POSSIBILITY OF SUCH DAMAGE. namespace libtorrent { - struct peer_connection; + class peer_connection; enum { @@ -340,7 +340,7 @@ namespace libtorrent TORRENT_ASSERT(index < m_files.num_pieces()); if (is_merkle_torrent()) { - TORRENT_ASSERT(index < int(m_merkle_tree.size()) - m_merkle_first_leaf); + TORRENT_ASSERT(index < int(m_merkle_tree.size() - m_merkle_first_leaf)); return (const char*)&m_merkle_tree[m_merkle_first_leaf + index][0]; } else @@ -348,7 +348,7 @@ namespace libtorrent TORRENT_ASSERT(m_piece_hashes); TORRENT_ASSERT(m_piece_hashes >= m_info_section.get()); TORRENT_ASSERT(m_piece_hashes < m_info_section.get() + m_info_section_size); - TORRENT_ASSERT(index < m_info_section_size / 20); + TORRENT_ASSERT(index < int(m_info_section_size / 20)); return &m_piece_hashes[index*20]; } } diff --git a/src/bandwidth_limit.cpp b/src/bandwidth_limit.cpp index 1013198df..7ab04fdec 100644 --- a/src/bandwidth_limit.cpp +++ b/src/bandwidth_limit.cpp @@ -52,7 +52,7 @@ namespace libtorrent int bandwidth_channel::quota_left() const { if (m_limit == 0) return inf; - return (std::max)(m_quota_left, boost::int64_t(0)); + return (std::max)(int(m_quota_left), 0); } void bandwidth_channel::update_quota(int dt_milliseconds) @@ -60,7 +60,7 @@ namespace libtorrent if (m_limit == 0) return; m_quota_left += (m_limit * dt_milliseconds + 500) / 1000; if (m_quota_left > m_limit * 3) m_quota_left = m_limit * 3; - distribute_quota = (std::max)(m_quota_left, boost::int64_t(0)); + distribute_quota = int((std::max)(m_quota_left, boost::int64_t(0))); // fprintf(stderr, "%p: [%d]: + %"PRId64" limit: %"PRId64" quota_left: %"PRId64"\n", this // , dt_milliseconds, (m_limit * dt_milliseconds + 500) / 1000, m_limit // , m_quota_left); diff --git a/src/create_torrent.cpp b/src/create_torrent.cpp index aac307d1e..3d65c8b5f 100644 --- a/src/create_torrent.cpp +++ b/src/create_torrent.cpp @@ -108,10 +108,10 @@ namespace libtorrent , m_creation_date(time(0)) , m_multifile(fs.num_files() > 1) , m_private(false) - , m_merkle_torrent(flags & merkle) - , m_include_mtime(flags & modification_time) - , m_include_symlinks(flags & symlinks) - , m_calculate_file_hashes(flags & calculate_file_hashes) + , m_merkle_torrent((flags & merkle) != 0) + , m_include_mtime((flags & modification_time) != 0) + , m_include_symlinks((flags & symlinks) != 0) + , m_calculate_file_hashes((flags & calculate_file_hashes) != 0) { TORRENT_ASSERT(fs.num_files() > 0); diff --git a/src/file_storage.cpp b/src/file_storage.cpp index 477fcec47..d4018f1df 100644 --- a/src/file_storage.cpp +++ b/src/file_storage.cpp @@ -200,10 +200,10 @@ namespace libtorrent e.size = size; e.path = file; e.offset = m_total_size; - e.pad_file = bool(flags & pad_file); - e.hidden_attribute = bool(flags & attribute_hidden); - e.executable_attribute = bool(flags & attribute_executable); - e.symlink_attribute = bool(flags & attribute_symlink); + e.pad_file = (flags & pad_file) != 0; + e.hidden_attribute = (flags & attribute_hidden) != 0; + e.executable_attribute = (flags & attribute_executable) != 0; + e.symlink_attribute = (flags & attribute_symlink) != 0; if (e.symlink_attribute) e.symlink_path = symlink_path; e.mtime = mtime; m_total_size += size; diff --git a/src/policy.cpp b/src/policy.cpp index 7b52130d2..e0845afde 100644 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -382,9 +382,9 @@ namespace libtorrent TORRENT_ASSERT(m_num_connect_candidates > 0); --m_num_connect_candidates; } - TORRENT_ASSERT(m_num_connect_candidates < m_peers.size()); + TORRENT_ASSERT(m_num_connect_candidates < int(m_peers.size())); if (m_round_robin > i - m_peers.begin()) --m_round_robin; - if (m_round_robin >= m_peers.size()) m_round_robin = 0; + if (m_round_robin >= int(m_peers.size())) m_round_robin = 0; #ifdef TORRENT_DEBUG TORRENT_ASSERT((*i)->in_use); @@ -454,10 +454,10 @@ namespace libtorrent for (int iterations = (std::min)(int(m_peers.size()), 300); iterations > 0; --iterations) { - if (m_peers.size() < max_peerlist_size * 0.95) + if (int(m_peers.size()) < max_peerlist_size * 0.95) break; - if (round_robin == m_peers.size()) round_robin = 0; + if (round_robin == int(m_peers.size())) round_robin = 0; peer& pe = *m_peers[round_robin]; int current = round_robin; @@ -470,7 +470,7 @@ namespace libtorrent if (should_erase_immediately(pe)) { if (erase_candidate > current) --erase_candidate; - TORRENT_ASSERT(current >= 0 && current < m_peers.size()); + TORRENT_ASSERT(current >= 0 && current < int(m_peers.size())); --round_robin; erase_peer(m_peers.begin() + current); } @@ -486,7 +486,7 @@ namespace libtorrent if (erase_candidate > -1) { - TORRENT_ASSERT(erase_candidate >= 0 && erase_candidate < m_peers.size()); + TORRENT_ASSERT(erase_candidate >= 0 && erase_candidate < int(m_peers.size())); erase_peer(m_peers.begin() + erase_candidate); } } @@ -563,7 +563,7 @@ namespace libtorrent external_ip = address_v4(bytes); } - if (m_round_robin >= m_peers.size()) m_round_robin = 0; + if (m_round_robin >= int(m_peers.size())) m_round_robin = 0; #ifndef TORRENT_DISABLE_DHT bool pinged = false; @@ -597,7 +597,7 @@ namespace libtorrent // if the number of peers is growing large // we need to start weeding. - if (m_peers.size() >= max_peerlist_size * 0.95 + if (int(m_peers.size()) >= max_peerlist_size * 0.95 && max_peerlist_size > 0) { if (is_erase_candidate(pe, m_finished) @@ -960,7 +960,7 @@ namespace libtorrent if (s) ++m_num_seeds; else --m_num_seeds; TORRENT_ASSERT(m_num_seeds >= 0); - TORRENT_ASSERT(m_num_seeds <= m_peers.size()); + TORRENT_ASSERT(m_num_seeds <= int(m_peers.size())); } bool policy::insert_peer(policy::peer* p, iterator iter, int flags) @@ -1288,7 +1288,6 @@ namespace libtorrent TORRENT_ASSERT(!is_connect_candidate(*p, m_finished)); // save transfer rate limits - int rate_limit; p->upload_rate_limit = c.upload_limit(); p->download_rate_limit = c.download_limit(); @@ -1374,7 +1373,7 @@ namespace libtorrent void policy::check_invariant() const { TORRENT_ASSERT(m_num_connect_candidates >= 0); - TORRENT_ASSERT(m_num_connect_candidates <= m_peers.size()); + TORRENT_ASSERT(m_num_connect_candidates <= int(m_peers.size())); if (m_torrent->is_aborted()) return; #ifdef TORRENT_EXPENSIVE_INVARIANT_CHECKS