From 75d61207f2e80dfab7aaa6cd6f215438d40faae0 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 17 Apr 2007 22:56:14 +0000 Subject: [PATCH] fix for prioritize_files() --- src/torrent.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/torrent.cpp b/src/torrent.cpp index 39c9ec0a1..cbc5743b8 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -1111,12 +1111,15 @@ namespace libtorrent for (int i = 0; i < int(files.size()); ++i) { size_type start = position; - position += m_torrent_file.file_at(i).size; + size_type size = m_torrent_file.file_at(i).size; + if (size == 0) continue; + position += size; // mark all pieces of the file with this file's priority // but only if the priority is higher than the pieces // already set (to avoid problems with overlapping pieces) int start_piece = int(start / piece_length); - int last_piece = int(position / piece_length); + int last_piece = int((position - 1) / piece_length); + assert(last_piece <= int(pieces.size())); // if one piece spans several files, we might // come here several times with the same start_piece, end_piece std::for_each(pieces.begin() + start_piece @@ -1134,8 +1137,6 @@ namespace libtorrent i->second->update_interest(); } - - void torrent::filter_piece(int index, bool filter) { INVARIANT_CHECK;