┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/kitemviews/kfileitemmodel.cpp
diff options
context:
space:
mode:
authorFrank Reininghaus <[email protected]>2014-06-04 21:48:19 +0200
committerFrank Reininghaus <[email protected]>2014-06-04 21:49:02 +0200
commit352f6441590a050099ee685b2284d1679f733c97 (patch)
treee9547883bc442b94569496931b3e22b5c0689fa7 /src/kitemviews/kfileitemmodel.cpp
parent96c34cfe650cef24bcfd6cfa6977c3b0ccb77281 (diff)
Fix possible crash if a kioslave adds multiple items with the same URL
When opening the URL "man:", there are multiple items with the same name (for example, _exit is shown twice here). When opening a new tab, the kioslave reports some items as deleted (I have not quite understood why). The problem is that it reports some of the duplicate items twice in the list of deleted items. This confused KFileItemModel and corrupted the internal data structures, and finally, caused a crash. The fix is to remove all duplicates from KItemRangeList::fromSortedContainer(const Container& container). New unit tests included. BUG: 335672 REVIEW: 118507 FIXED-IN: 4.13.2
Diffstat (limited to 'src/kitemviews/kfileitemmodel.cpp')
-rw-r--r--src/kitemviews/kfileitemmodel.cpp36
1 files changed, 35 insertions, 1 deletions
diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp
index de3c3eb22..b3b926c3a 100644
--- a/src/kitemviews/kfileitemmodel.cpp
+++ b/src/kitemviews/kfileitemmodel.cpp
@@ -395,7 +395,41 @@ int KFileItemModel::index(const KUrl& url) const
index = m_items.value(urlToFind, -1);
}
- Q_ASSERT(index >= 0 || m_items.count() == m_itemData.count());
+ if (index < 0) {
+ // The item could not be found, even though all items from m_itemData
+ // should be in m_items now. We print some diagnostic information which
+ // might help to find the cause of the problem, but only once. This
+ // prevents that obtaining and printing the debugging information
+ // wastes CPU cycles and floods the shell or .xsession-errors.
+ static bool printDebugInfo = true;
+
+ if (m_items.count() != m_itemData.count() && printDebugInfo) {
+ printDebugInfo = false;
+
+ kWarning() << "The model is in an inconsistent state.";
+ kWarning() << "m_items.count() ==" << m_items.count();
+ kWarning() << "m_itemData.count() ==" << m_itemData.count();
+
+ // Check if there are multiple items with the same URL.
+ QMultiHash<KUrl, int> indexesForUrl;
+ for (int i = 0; i < m_itemData.count(); ++i) {
+ indexesForUrl.insert(m_itemData.at(i)->item.url(), i);
+ }
+
+ foreach (const KUrl& url, indexesForUrl.uniqueKeys()) {
+ if (indexesForUrl.count(url) > 1) {
+ kWarning() << "Multiple items found with the URL" << url;
+ foreach (int index, indexesForUrl.values(url)) {
+ const ItemData* data = m_itemData.at(index);
+ kWarning() << "index" << index << ":" << data->item;
+ if (data->parent) {
+ kWarning() << "parent" << data->parent->item;
+ }
+ }
+ }
+ }
+ }
+ }
return index;
}