From 9a8367c00c12ca589fad97c931352856a9527a1f Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Fri, 4 Jul 2014 13:23:37 +0200 Subject: [PATCH] Bugfix. Too many elements were trimmed from the end of the lists due to a wrong calculation of the last unused chunk length. --- src/observersmanager.hpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/observersmanager.hpp b/src/observersmanager.hpp index 38a6934..680c571 100644 --- a/src/observersmanager.hpp +++ b/src/observersmanager.hpp @@ -136,9 +136,14 @@ namespace cloonel { m_occupied[parTicket - 1] = false; --m_usedCount; - auto lastNull = std::find(m_occupied.rbegin(), m_occupied.rend(), false); - if (m_occupied.rend() != lastNull) { - const std::size_t newSize = m_occupied.size() - static_cast(lastNull - m_occupied.rbegin()) + 1; + std::size_t deleCount = 0; + for (auto itOcc = m_occupied.rbegin(), itOccEND = m_occupied.rend(); itOcc != itOccEND and not *itOcc; ++itOcc) { + ++deleCount; + } + + if (deleCount) { + assert(deleCount <= m_occupied.size()); + const std::size_t newSize = m_occupied.size() - deleCount; m_occupied.resize(newSize); m_list.resize(newSize); }