From f029f5d6b2eaa55dd4248716ece6ee79da3cf66b Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Mon, 2 Oct 2006 08:58:28 +0000 Subject: [PATCH] fixed sequenced download bug --- ChangeLog | 2 ++ src/piece_picker.cpp | 23 ++++++++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 95a853cec..ad6f28557 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,5 @@ + * fixed bug occuring when increasing the sequenced download threshold + with max availability lower than previous threshold. * fixed an integer overflow bug occuring when built with gcc 4.1.x * fixed crasing bug when closing while checking a torrent * fixed bug causing a crash with a torrent with piece length 0 diff --git a/src/piece_picker.cpp b/src/piece_picker.cpp index 4c35258e6..50a57cd74 100755 --- a/src/piece_picker.cpp +++ b/src/piece_picker.cpp @@ -166,20 +166,25 @@ namespace libtorrent if (old_limit < sequenced_download_threshold) { - assert(int(m_piece_info.size()) > old_limit); - info_t& in = m_piece_info[old_limit]; - std::random_shuffle(in.begin(), in.end()); - int c = 0; - for (info_t::iterator i = in.begin() - , end(in.end()); i != end; ++i) + // the threshold was incremented, in case + // the previous max availability was reached + // we need to shuffle that bucket, if not, we + // don't have to do anything + if (int(m_piece_info.size()) > old_limit) { - m_piece_map[*i].index = c++; - assert(m_piece_map[*i].priority(old_limit) == old_limit); + info_t& in = m_piece_info[old_limit]; + std::random_shuffle(in.begin(), in.end()); + int c = 0; + for (info_t::iterator i = in.begin() + , end(in.end()); i != end; ++i) + { + m_piece_map[*i].index = c++; + assert(m_piece_map[*i].priority(old_limit) == old_limit); + } } } else if (int(m_piece_info.size()) > sequenced_download_threshold) { - assert(int(m_piece_info.size()) > sequenced_download_threshold); info_t& in = m_piece_info[sequenced_download_threshold]; std::sort(in.begin(), in.end()); int c = 0;