diff options
author | Olivier Goffart <olivier.goffart@nokia.com> | 2010-05-17 15:43:16 (GMT) |
---|---|---|
committer | Olivier Goffart <olivier.goffart@nokia.com> | 2010-05-17 15:43:16 (GMT) |
commit | 01e7389086d4afde33c3e2b1ece9c6d906869e08 (patch) | |
tree | ffde29bb4c2f5cd50a59561cf9533f1fd2d301ff | |
parent | 6126d5c033e669bd57fc26093eb9be368feb12e2 (diff) | |
download | Qt-01e7389086d4afde33c3e2b1ece9c6d906869e08.zip Qt-01e7389086d4afde33c3e2b1ece9c6d906869e08.tar.gz Qt-01e7389086d4afde33c3e2b1ece9c6d906869e08.tar.bz2 |
QCompleter: fix misuse of QMap that can lead to crashes
Patch providedin the task.
Task-number: QTBUG-8407
-rw-r--r-- | src/gui/util/qcompleter.cpp | 17 |
1 files 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<QModelIndex, CacheItem>::iterator it1 ; - for (it1 = cache.begin(); it1 != cache.end(); ++it1) { + QMap<QModelIndex, CacheItem>::iterator it1 = cache.begin(); + while (it1 != cache.end()) { CacheItem& ci = it1.value(); int sz = ci.count()/2; QMap<QString, QMatchData>::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); } } |