diff --git a/include/libtorrent/bencode.hpp b/include/libtorrent/bencode.hpp index fc0451242..29c7e2080 100755 --- a/include/libtorrent/bencode.hpp +++ b/include/libtorrent/bencode.hpp @@ -132,7 +132,7 @@ namespace libtorrent template std::string read_string(InIt& in, InIt end, int len) { - assert(len>=0); + assert(len >= 0); std::string ret; for (int i = 0; i < len; ++i) { diff --git a/include/libtorrent/hasher.hpp b/include/libtorrent/hasher.hpp index f5de4ef9e..532ef5587 100755 --- a/include/libtorrent/hasher.hpp +++ b/include/libtorrent/hasher.hpp @@ -61,7 +61,11 @@ namespace libtorrent adler32_crc(): m_adler(adler32(0, 0, 0)) {} void update(const char* data, int len) - { assert(data); assert(len>0); m_adler = adler32(m_adler, data, len); } + { + assert(data != 0); + assert(len > 0); + m_adler = adler32(m_adler, data, len); + } unsigned long final() const { return m_adler; } void reset() { m_adler = adler32(0, 0, 0); } @@ -77,7 +81,11 @@ namespace libtorrent hasher() { SHA1Init(&m_context); } void update(const char* data, int len) - { assert(data); assert(len>0); SHA1Update(&m_context, reinterpret_cast(const_cast(data)), len); } + { + assert(data != 0); + assert(len > 0); + SHA1Update(&m_context, reinterpret_cast(const_cast(data)), len); + } sha1_hash final() { diff --git a/include/libtorrent/peer_connection.hpp b/include/libtorrent/peer_connection.hpp index 86298e5df..77b61729e 100755 --- a/include/libtorrent/peer_connection.hpp +++ b/include/libtorrent/peer_connection.hpp @@ -255,8 +255,11 @@ namespace libtorrent const peer_id& id() const { return m_peer_id; } bool has_piece(int i) const - { assert(i >= 0 && i < m_torrent->torrent_file().num_pieces()); - return m_have_piece[i]; } + { + assert(i >= 0); + assert(i < m_torrent->torrent_file().num_pieces()); + return m_have_piece[i]; + } const std::deque& download_queue() const { return m_download_queue; } @@ -460,7 +463,13 @@ namespace libtorrent // seperately on payload and protocol data. struct range { - range(int s, int l): start(s), length(l) { assert(s>=0); assert(l>0);} + range(int s, int l) + : start(s) + , length(l) + { + assert(s >= 0); + assert(l > 0); + } int start; int length; }; diff --git a/include/libtorrent/piece_picker.hpp b/include/libtorrent/piece_picker.hpp index b7d4ae9ff..db1f7128d 100755 --- a/include/libtorrent/piece_picker.hpp +++ b/include/libtorrent/piece_picker.hpp @@ -62,7 +62,10 @@ namespace libtorrent piece_block(int p_index, int b_index) : piece_index(p_index) , block_index(b_index) - { assert(p_index>=0); assert(b_index>=0); } + { + assert(p_index >= 0); + assert(b_index >= 0); + } int piece_index; int block_index; bool operator==(const piece_block& b) const @@ -191,7 +194,7 @@ namespace libtorrent // functor that compares indices on downloading_pieces struct has_index { - has_index(int i): index(i) { assert(i>=0); } + has_index(int i): index(i) { assert(i >= 0); } bool operator()(const downloading_piece& p) const { return p.index == index; } int index; @@ -209,7 +212,10 @@ namespace libtorrent : peer_count(peer_count_) , downloading(0) , index(index_) - { assert(peer_count_>=0); assert(index_>=0); } + { + assert(peer_count_ >= 0); + assert(index_ >= 0); + } // selects which vector to look in unsigned peer_count : 7; @@ -267,7 +273,8 @@ namespace libtorrent inline int piece_picker::blocks_in_piece(int index) const { - assert(index>=0 && (unsigned)index < m_piece_map.size()); + assert(index >= 0); + assert(index < (int)m_piece_map.size()); if (index+1 == m_piece_map.size()) return m_blocks_in_last_piece; else diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 2f5df413e..58ce3fc6a 100755 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -205,11 +205,15 @@ namespace libtorrent void peer_connection::set_send_quota(int num_bytes) { - assert(num_bytes>=0 || num_bytes==-1); INVARIANT_CHECK; + assert(num_bytes >= 0 || num_bytes == -1); + + if (num_bytes > m_send_quota_limit + && m_send_quota_limit != -1) + num_bytes = m_send_quota_limit; + assert(num_bytes <= m_send_quota_limit || m_send_quota_limit == -1); - if (num_bytes > m_send_quota_limit && m_send_quota_limit!=-1) num_bytes = m_send_quota_limit; m_send_quota = num_bytes; m_send_quota_left = num_bytes; @@ -322,9 +326,9 @@ namespace libtorrent void peer_connection::on_choke(int received) { - assert(received>0); INVARIANT_CHECK; + assert(received > 0); if (m_packet_size != 1) throw protocol_error("'choke' message size != 1"); m_statistics.received_bytes(0, received); @@ -356,9 +360,9 @@ namespace libtorrent void peer_connection::on_unchoke(int received) { - assert(received>0); INVARIANT_CHECK; + assert(received > 0); if (m_packet_size != 1) throw protocol_error("'unchoke' message size != 1"); m_statistics.received_bytes(0, received); @@ -377,9 +381,9 @@ namespace libtorrent void peer_connection::on_interested(int received) { - assert(received>0); INVARIANT_CHECK; + assert(received > 0); if (m_packet_size != 1) throw protocol_error("'interested' message size != 1"); m_statistics.received_bytes(0, received); @@ -398,9 +402,9 @@ namespace libtorrent void peer_connection::on_not_interested(int received) { - assert(received>0); INVARIANT_CHECK; + assert(received > 0); if (m_packet_size != 1) throw protocol_error("'not interested' message size != 1"); m_statistics.received_bytes(0, received); @@ -422,9 +426,9 @@ namespace libtorrent void peer_connection::on_have(int received) { - assert(received>0); INVARIANT_CHECK; + assert(received > 0); if (m_packet_size != 5) throw protocol_error("'have' message size != 5"); m_statistics.received_bytes(0, received); @@ -467,9 +471,9 @@ namespace libtorrent void peer_connection::on_bitfield(int received) { - assert(received>0); INVARIANT_CHECK; + assert(received > 0); if (m_packet_size - 1 != (m_have_piece.size() + 7) / 8) throw protocol_error("bitfield with invalid size"); m_statistics.received_bytes(0, received); @@ -535,9 +539,9 @@ namespace libtorrent void peer_connection::on_request(int received) { - assert(received>0); INVARIANT_CHECK; + assert(received > 0); if (m_packet_size != 13) throw protocol_error("'request' message size != 13"); m_statistics.received_bytes(0, received); @@ -603,9 +607,9 @@ namespace libtorrent void peer_connection::on_piece(int received) { - assert(received>0); INVARIANT_CHECK; + assert(received > 0); if (m_recv_pos - received <= 9) { m_last_piece = boost::posix_time::second_clock::local_time(); @@ -751,9 +755,9 @@ namespace libtorrent void peer_connection::on_cancel(int received) { - assert(received>0); INVARIANT_CHECK; + assert(received > 0); if (m_packet_size != 13) throw protocol_error("'cancel' message size != 13"); m_statistics.received_bytes(0, received); @@ -789,9 +793,9 @@ namespace libtorrent void peer_connection::on_extension_list(int received) { - assert(received>0); INVARIANT_CHECK; + assert(received > 0); if (m_packet_size > 100 * 1024) { // too big extension message, abort @@ -840,9 +844,9 @@ namespace libtorrent void peer_connection::on_extended(int received) { - assert(received>0); INVARIANT_CHECK; + assert(received > 0); m_statistics.received_bytes(0, received); if (m_packet_size < 5) throw protocol_error("'extended' message smaller than 5 bytes"); @@ -916,12 +920,12 @@ namespace libtorrent bool peer_connection::dispatch_message(int received) { - assert(received>0); INVARIANT_CHECK; + assert(received > 0); assert(m_recv_pos >= received); assert(m_recv_pos > 0); - assert(m_torrent); + assert(m_torrent != 0); int packet_type = m_recv_buffer[0]; if (packet_type < 0 @@ -1555,7 +1559,7 @@ namespace libtorrent // requested block. Have a limit of how much of the requested // block is actually read at a time. while (!m_requests.empty() - && (m_send_buffer.size() < (unsigned)m_torrent->block_size()) + && ((int)m_send_buffer.size() < m_torrent->block_size()) && !m_choked) { peer_request& r = m_requests.front(); diff --git a/src/piece_picker.cpp b/src/piece_picker.cpp index 772aa3ee2..ee5682399 100755 --- a/src/piece_picker.cpp +++ b/src/piece_picker.cpp @@ -59,8 +59,8 @@ namespace libtorrent , m_downloading_piece_info(2) , m_piece_map((total_num_blocks + blocks_per_piece-1) / blocks_per_piece) { - assert(blocks_per_piece>0); - assert(total_num_blocks>0); + assert(blocks_per_piece > 0); + assert(total_num_blocks > 0); m_blocks_per_piece = blocks_per_piece; m_blocks_in_last_piece = total_num_blocks % blocks_per_piece; @@ -103,7 +103,8 @@ namespace libtorrent ++i) { int index = *i; - assert(index >= 0 && index < (int)m_piece_map.size()); + assert(index >= 0); + assert(index < (int)m_piece_map.size()); assert(m_piece_map[index].index == 0xffffff); int peer_count = m_piece_map[index].peer_count; @@ -393,7 +394,9 @@ namespace libtorrent void piece_picker::we_have(int index) { - assert(index >= 0 && index < (int)m_piece_map.size()); + assert(index >= 0); + assert(index < (int)m_piece_map.size()); + int info_index = m_piece_map[index].index; int peer_count = m_piece_map[index].peer_count; @@ -410,7 +413,7 @@ namespace libtorrent std::vector& interesting_pieces, int num_blocks) const { - assert(num_blocks>0); + assert(num_blocks > 0); assert(pieces.size() == m_piece_map.size()); #ifndef NDEBUG @@ -452,7 +455,7 @@ namespace libtorrent std::vector& interesting_blocks, int num_blocks) const { - assert(num_blocks>0); + assert(num_blocks > 0); for (std::vector::const_iterator i = piece_list.begin(); i != piece_list.end();