From 365b8c07c6c6dc7945dfdf1d19e479f18cf67d64 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 19 Jan 2008 18:12:02 +0000 Subject: [PATCH] iterator fixes (to avoid triggering safe iterator asserts) --- include/libtorrent/bandwidth_manager.hpp | 11 +++++++---- src/torrent.cpp | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/include/libtorrent/bandwidth_manager.hpp b/include/libtorrent/bandwidth_manager.hpp index 706fc1d90..7b3d0214b 100644 --- a/include/libtorrent/bandwidth_manager.hpp +++ b/include/libtorrent/bandwidth_manager.hpp @@ -222,10 +222,13 @@ struct bandwidth_manager TORRENT_ASSERT(current_quota == m_current_quota); typename queue_t::const_iterator j = m_queue.begin(); - ++j; - for (typename queue_t::const_iterator i = m_queue.begin() - , end(m_queue.end()); i != end && j != end; ++i, ++j) - TORRENT_ASSERT(i->priority >= j->priority); + if (j != m_queue.end()) + { + ++j; + for (typename queue_t::const_iterator i = m_queue.begin() + , end(m_queue.end()); i != end && j != end; ++i, ++j) + TORRENT_ASSERT(i->priority >= j->priority); + } } #endif diff --git a/src/torrent.cpp b/src/torrent.cpp index 61aaa4785..48af6cf7e 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -2681,6 +2681,7 @@ namespace libtorrent for (int c = 0; c < 2; ++c) { queue_t::const_iterator j = m_bandwidth_queue[c].begin(); + if (j == m_bandwidth_queue[c].end()) continue; ++j; for (queue_t::const_iterator i = m_bandwidth_queue[c].begin() , end(m_bandwidth_queue[c].end()); i != end && j != end; ++i, ++j)