From c4c1773cebab2168da5bef1a9d8577f49bd7bef8 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 15 Feb 2011 10:05:25 +0000 Subject: [PATCH] fixed some warnings --- src/file.cpp | 3 +++ src/http_seed_connection.cpp | 4 ++-- src/natpmp.cpp | 2 +- src/packet_buffer.cpp | 4 ++-- src/peer_connection.cpp | 6 ++---- src/piece_picker.cpp | 2 +- src/policy.cpp | 7 +------ src/session_impl.cpp | 11 +++++------ src/storage.cpp | 4 ++-- src/torrent_info.cpp | 1 + src/web_peer_connection.cpp | 5 +++-- 11 files changed, 23 insertions(+), 26 deletions(-) diff --git a/src/file.cpp b/src/file.cpp index 9ebbe12df..f94daee36 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -1572,7 +1572,10 @@ namespace libtorrent } #endif // F_PREALLOCATE +#if defined TORRENT_LINUX || defined TORRENT_HAS_FALLOCATE int ret; +#endif + #if defined TORRENT_LINUX ret = my_fallocate(m_fd, 0, 0, s); // if we return 0, everything went fine diff --git a/src/http_seed_connection.cpp b/src/http_seed_connection.cpp index fbc1b29ba..532ea2493 100644 --- a/src/http_seed_connection.cpp +++ b/src/http_seed_connection.cpp @@ -362,7 +362,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(bytes_transferred >= size_t(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(); @@ -374,7 +374,7 @@ 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(bytes_transferred >= size_t(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; diff --git a/src/natpmp.cpp b/src/natpmp.cpp index d89642ef7..d0d516474 100644 --- a/src/natpmp.cpp +++ b/src/natpmp.cpp @@ -297,7 +297,7 @@ void natpmp::try_next_mapping(int i, mutex::scoped_lock& l) void natpmp::update_mapping(int i, mutex::scoped_lock& l) { - if (i == m_mappings.size()) + if (i == int(m_mappings.size())) { if (m_abort) { diff --git a/src/packet_buffer.cpp b/src/packet_buffer.cpp index c9745f978..f7f6a6b48 100644 --- a/src/packet_buffer.cpp +++ b/src/packet_buffer.cpp @@ -193,7 +193,7 @@ namespace libtorrent { if (idx == m_first && m_size != 0) { ++m_first; - for (int i = 0; i < m_capacity; ++i, ++m_first) + for (boost::uint32_t i = 0; i < m_capacity; ++i, ++m_first) if (m_storage[m_first & mask]) break; m_first &= 0xffff; } @@ -201,7 +201,7 @@ namespace libtorrent { if (((idx + 1) & 0xffff) == m_last && m_size != 0) { --m_last; - for (int i = 0; i < m_capacity; ++i, --m_last) + for (boost::uint32_t i = 0; i < m_capacity; ++i, --m_last) if (m_storage[m_last & mask]) break; ++m_last; m_last &= 0xffff; diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index e5fed9a72..3333fca0a 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -4984,11 +4984,10 @@ namespace libtorrent return; } - int max_receive = 0; int num_loops = 0; do { - TORRENT_ASSERT(m_recv_pos + bytes_transferred <= m_packet_size); + TORRENT_ASSERT(int(m_recv_pos + bytes_transferred) <= m_packet_size); #ifdef TORRENT_VERBOSE_LOGGING peer_log("<<< read %d bytes", int(bytes_transferred)); #endif @@ -5369,7 +5368,7 @@ namespace libtorrent void peer_connection::check_invariant() const { - TORRENT_ASSERT(m_queued_time_critical <= m_request_queue.size()); + TORRENT_ASSERT(m_queued_time_critical <= int(m_request_queue.size())); TORRENT_ASSERT(bool(m_disk_recv_buffer) == (m_disk_recv_buffer_size > 0)); @@ -5400,7 +5399,6 @@ namespace libtorrent int block_size = t->block_size(); piece_block last_block(ti.num_pieces()-1 , (ti.piece_size(ti.num_pieces()-1) + block_size - 1) / block_size); - int last_block_size = t->torrent_file().piece_size(ti.num_pieces()-1) - last_block.block_index * block_size; for (std::vector::const_iterator i = m_download_queue.begin() , end(m_download_queue.end()); i != end; ++i) { diff --git a/src/piece_picker.cpp b/src/piece_picker.cpp index 14bd69227..3cb0ec9c3 100644 --- a/src/piece_picker.cpp +++ b/src/piece_picker.cpp @@ -1104,7 +1104,7 @@ namespace libtorrent // maintain sparse_regions if (index == 0) { - if (index == m_piece_map.size() - 1 + if (index == int(m_piece_map.size()) - 1 || m_piece_map[index + 1].have()) --m_sparse_regions; } diff --git a/src/policy.cpp b/src/policy.cpp index 19c323521..866e2698e 100644 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -228,7 +228,7 @@ namespace libtorrent // also, if we already have at least one outstanding // request, we shouldn't pick any busy pieces either bool dont_pick_busy_blocks = (ses.m_settings.strict_end_game_mode - && p.num_have() + p.get_download_queue().size() + && p.num_have() + int(p.get_download_queue().size()) < t.torrent_file().num_pieces()) || dq.size() + rq.size() > 0; @@ -1115,7 +1115,6 @@ namespace libtorrent policy::peer* policy::add_i2p_peer(char const* destination, int src, char flags) { INVARIANT_CHECK; - aux::session_impl& ses = m_torrent->session(); bool found = false; iterator iter = std::lower_bound( @@ -1206,10 +1205,6 @@ namespace libtorrent iterator iter; peer* p = 0; - int max_peerlist_size = m_torrent->is_paused() - ?m_torrent->settings().max_paused_peerlist_size - :m_torrent->settings().max_peerlist_size; - bool found = false; if (m_torrent->settings().allow_multiple_connections_per_ip) { diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 742c97f3f..dd7eae569 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -650,8 +650,8 @@ namespace aux { char tmp[300]; snprintf(tmp, sizeof(tmp), "libtorrent configuration: %s\n" - "libtorrent version: %d\n" - "libtorrent revision: %d\n\n" + "libtorrent version: %s\n" + "libtorrent revision: %s\n\n" , TORRENT_CFG_STRING , LIBTORRENT_VERSION , LIBTORRENT_REVISION); @@ -988,7 +988,7 @@ namespace aux { all_default_values def; - for (int i = 0; i < sizeof(all_settings)/sizeof(all_settings[0]); ++i) + for (int i = 0; i < int(sizeof(all_settings)/sizeof(all_settings[0])); ++i) { session_category const& c = all_settings[i]; if ((flags & c.flag) == 0) continue; @@ -1070,7 +1070,7 @@ namespace aux { if (e->type() != lazy_entry::dict_t) return; - for (int i = 0; i < sizeof(all_settings)/sizeof(all_settings[0]); ++i) + for (int i = 0; i < int(sizeof(all_settings)/sizeof(all_settings[0])); ++i) { session_category const& c = all_settings[i]; settings = e->dict_find_dict(c.name); @@ -2964,7 +2964,7 @@ namespace aux { m_cache_rotation_timer = m_settings.explicit_cache_interval; torrent_map::iterator least_recently_refreshed = m_torrents.begin(); - if (m_next_explicit_cache_torrent >= m_torrents.size()) + if (m_next_explicit_cache_torrent >= int(m_torrents.size())) m_next_explicit_cache_torrent = 0; std::advance(least_recently_refreshed, m_next_explicit_cache_torrent); @@ -3528,7 +3528,6 @@ namespace aux { { if (!p->is_choked() && p->is_interesting()) { - policy::peer* pi = p->peer_info_struct(); if (!p->has_peer_choked()) { // we're unchoked, we may want to lower our estimated diff --git a/src/storage.cpp b/src/storage.cpp index 84d2c25fa..c5c94ef32 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -460,7 +460,7 @@ namespace libtorrent ph.h.update((char const*)bufs[i].iov_base, small_piece_size); *small_hash = hasher(ph.h).final(); small_hash = 0; // avoid this case again - if (bufs[i].iov_len > small_piece_size) + if (int(bufs[i].iov_len) > small_piece_size) ph.h.update((char const*)bufs[i].iov_base + small_piece_size , bufs[i].iov_len - small_piece_size); } @@ -491,7 +491,7 @@ namespace libtorrent if (small_piece_size > 0) ph.h.update((char const*)buf.iov_base, small_piece_size); *small_hash = hasher(ph.h).final(); small_hash = 0; // avoid this case again - if (buf.iov_len > small_piece_size) + if (int(buf.iov_len) > small_piece_size) ph.h.update((char const*)buf.iov_base + small_piece_size , buf.iov_len - small_piece_size); } diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index 3148fd7aa..9cb6db867 100644 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -481,6 +481,7 @@ namespace libtorrent memcpy(m_info_section.get(), t.m_info_section.get(), m_info_section_size); int ret = lazy_bdecode(m_info_section.get(), m_info_section.get() + m_info_section_size, m_info_dict, ec); + TORRENT_ASSERT(ret == 0); lazy_entry const* pieces = m_info_dict.dict_find_string("pieces"); if (pieces && pieces->string_length() == m_files.num_pieces() * 20) diff --git a/src/web_peer_connection.cpp b/src/web_peer_connection.cpp index c70a24292..46dc4b846 100644 --- a/src/web_peer_connection.cpp +++ b/src/web_peer_connection.cpp @@ -78,7 +78,6 @@ namespace libtorrent shared_ptr tor = t.lock(); TORRENT_ASSERT(tor); - int blocks_per_piece = tor->torrent_file().piece_length() / tor->block_size(); // we always prefer downloading 1 MB chunks // from web seeds @@ -266,7 +265,9 @@ namespace libtorrent INVARIANT_CHECK; #ifdef TORRENT_DEBUG - size_type dl_target = m_statistics.last_payload_downloaded() + TORRENT_ASSERT(m_statistics.last_payload_downloaded() + + m_statistics.last_protocol_downloaded() + bytes_transferred < size_t(INT_MAX)); + int dl_target = m_statistics.last_payload_downloaded() + m_statistics.last_protocol_downloaded() + bytes_transferred; #endif