From d9db8e20f541fc69fa7c6636dcaac876b9d748b9 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Fri, 17 Feb 2012 07:19:54 +0000 Subject: [PATCH] fix another pad file corner case --- src/torrent.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/torrent.cpp b/src/torrent.cpp index 9ecc12702..9aebcc689 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -2813,14 +2813,20 @@ namespace libtorrent { if (!i->pad_file) continue; peer_request p = files.map_file(fileno, 0, i->size); - for (int j = p.piece; p.length > 0; ++j, p.length -= piece_size) + for (int j = p.piece; p.length > 0; ++j) { - int deduction = (std::min)(p.length, piece_size); + int deduction = (std::min)(p.length, piece_size - p.start); bool done = m_picker->have_piece(j); bool wanted = m_picker->piece_priority(j) > 0; if (done) st.total_done -= deduction; if (wanted) st.total_wanted -= deduction; if (wanted && done) st.total_wanted_done -= deduction; + TORRENT_ASSERT(st.total_done >= 0); + TORRENT_ASSERT(st.total_wanted >= 0); + TORRENT_ASSERT(st.total_wanted_done >= 0); + p.length -= piece_size - p.start; + p.start = 0; + ++p.piece; } } }