From 01e7389086d4afde33c3e2b1ece9c6d906869e08 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Mon, 17 May 2010 17:43:16 +0200 Subject: QCompleter: fix misuse of QMap that can lead to crashes Patch providedin the task. Task-number: QTBUG-8407 --- src/gui/util/qcompleter.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/gui/util/qcompleter.cpp b/src/gui/util/qcompleter.cpp index cefdb27..ce2eff5 100644 --- a/src/gui/util/qcompleter.cpp +++ b/src/gui/util/qcompleter.cpp @@ -527,17 +527,22 @@ void QCompletionEngine::saveInCache(QString part, const QModelIndex& parent, con QMatchData old = cache[parent].take(part); cost = cost + m.indices.cost() - old.indices.cost(); if (cost * sizeof(int) > 1024 * 1024) { - QMap::iterator it1 ; - for (it1 = cache.begin(); it1 != cache.end(); ++it1) { + QMap::iterator it1 = cache.begin(); + while (it1 != cache.end()) { CacheItem& ci = it1.value(); int sz = ci.count()/2; QMap::iterator it2 = ci.begin(); - for (int i = 0; it2 != ci.end() && i < sz; i++, ++it2) { + int i = 0; + while (it2 != ci.end() && i < sz) { cost -= it2.value().indices.cost(); - ci.erase(it2); + it2 = ci.erase(it2); + i++; + } + if (ci.count() == 0) { + it1 = cache.erase(it1); + } else { + ++it1; } - if (ci.count() == 0) - cache.erase(it1); } } -- cgit v0.12