diff --git a/include/libtorrent/torrent_info.hpp b/include/libtorrent/torrent_info.hpp index a1e7019e8..eb7bc8f6f 100755 --- a/include/libtorrent/torrent_info.hpp +++ b/include/libtorrent/torrent_info.hpp @@ -116,8 +116,8 @@ namespace libtorrent // the begining) and return the new index to the tracker. int prioritize_tracker(int index); - size_type total_size() const { return m_total_size; } - size_type piece_length() const { return m_piece_length; } + size_type total_size() const { assert(m_total_size>=0); return m_total_size; } + size_type piece_length() const { assert(m_piece_length>0); return m_piece_length; } int num_pieces() const { return (int)m_piece_hash.size(); } const sha1_hash& info_hash() const { return m_info_hash; } const std::string& name() const { return m_name; } diff --git a/src/storage.cpp b/src/storage.cpp index 2bf8bb282..2221148c0 100755 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -638,9 +638,9 @@ namespace libtorrent assert(offset >= 0); assert(size > 0); assert(piece_index >= 0 && (unsigned)piece_index < m_piece_to_slot.size()); - assert(m_piece_to_slot[piece_index] >= 0); + assert(m_piece_to_slot[piece_index] >= 0 && (unsigned)m_piece_to_slot[piece_index] < m_slot_to_piece.size()); int slot = m_piece_to_slot[piece_index]; - assert(slot >= 0 && slot < (int)m_slot_to_piece.size()); + assert(slot >= 0 && (unsigned)slot < m_slot_to_piece.size()); return m_storage.read(buf, slot, offset, size); } @@ -663,7 +663,6 @@ namespace libtorrent assert(offset >= 0); assert(size > 0); assert(piece_index >= 0 && (unsigned)piece_index < m_piece_to_slot.size()); - assert(m_piece_to_slot[piece_index] >= 0); int slot = allocate_slot_for_piece(piece_index); assert(slot >= 0 && (unsigned)slot < m_slot_to_piece.size()); m_storage.write(buf, slot, offset, size); @@ -942,6 +941,27 @@ namespace libtorrent bytes_to_read = m_info.piece_size(current_slot); } + // dirty "fix" for a bug when file is corrupt + for(int i=0;(unsigned)i=0 && (unsigned)m_piece_to_slot[i]=0 && (unsigned)m_slot_to_piece[i]=0 && (unsigned)m_piece_to_slot[i]=0 && (unsigned)m_slot_to_piece[i]=0) { assert(m_slot_to_piece[m_piece_to_slot[i]]==i); diff --git a/src/torrent.cpp b/src/torrent.cpp index 48d1242d3..793c4fdd3 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -614,7 +614,7 @@ namespace libtorrent void torrent::check_files(detail::piece_checker_data& data, boost::mutex& mutex) { - m_storage.check_pieces(mutex, data, m_have_pieces); + m_storage.check_pieces(mutex, data, m_have_pieces); m_num_pieces = std::accumulate( m_have_pieces.begin() , m_have_pieces.end() diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index 147b06728..3bfecc255 100755 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -235,7 +235,8 @@ namespace libtorrent int torrent_info::prioritize_tracker(int index) { - if (index > (int)m_urls.size()) return (int)m_urls.size()-1; + assert(index >= 0); + if (index >= (int)m_urls.size()) return (int)m_urls.size()-1; while (index > 0 && m_urls[index].tier == m_urls[index-1].tier) {