fixed some msvc warnings

This commit is contained in:
Arvid Norberg 2010-10-16 15:24:45 +00:00
parent 7be0604877
commit 559c4bdf65
9 changed files with 32 additions and 29 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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