Skip to content
Snippets Groups Projects
Commit 66f7cebc authored by Pierre Lamot's avatar Pierre Lamot Committed by Steve Lhomme
Browse files

qt: fix out of bound when deleting range from model

view may request data that are not loaded in then cache to be deleted
parent 7b115a86
No related branches found
No related tags found
1 merge request!3792qt: fix out of bound when deleting range from model
Pipeline #354706 passed with stage
in 38 minutes and 31 seconds
......@@ -230,14 +230,26 @@ void MLListCache::deleteRange(int first, int last)
{
if (unlikely(!m_cachedData))
return;
assert(first <= last);
assert(first >= 0);
assert(static_cast<size_t>(last) < m_cachedData->totalCount);
emit beginRemoveRows(first, last);
auto it = m_cachedData->list.begin();
m_cachedData->list.erase(it+first, it+(last+1));
size_t delta = m_cachedData->loadedCount - m_cachedData->list.size();
m_cachedData->loadedCount -= delta;
m_cachedData->totalCount -= delta;
if (static_cast<size_t>(first) < m_cachedData->loadedCount)
{
auto itFirst = std::next(m_cachedData->list.begin(), first);
auto itLast = m_cachedData->list.begin();
if (static_cast<size_t>(last) < m_cachedData->loadedCount)
itLast = std::next(itLast, last + 1);
else
itLast = m_cachedData->list.end();
m_cachedData->list.erase(itFirst, itLast);
m_cachedData->loadedCount = m_cachedData->list.size();
}
//else data are not loaded, just mark them as deleted
m_cachedData->totalCount -= (last + 1) - first;
emit endRemoveRows();
emit localSizeChanged(m_cachedData->totalCount);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment