From 90cf4988ea16784a95126e23ea64913711622465 Mon Sep 17 00:00:00 2001 From: Jim Broadus Date: Sun, 23 Feb 2020 23:20:30 -0800 Subject: [PATCH] Fix crash when searching playlist. While iterating over expandList in refreshExpanded, calls to setExpanded cause the list to be appended. Since QList uses an array implementation that must reallocate when reserved space is exhausted, iterators are unsafe for this case. Use indexes, which are O(1) in QLists, instead of iterators. --- src/playlist/playlistlistcontainer.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/playlist/playlistlistcontainer.cpp b/src/playlist/playlistlistcontainer.cpp index 14e0da305..4fd8ac9fb 100644 --- a/src/playlist/playlistlistcontainer.cpp +++ b/src/playlist/playlistlistcontainer.cpp @@ -67,7 +67,13 @@ class PlaylistListFilterProxyModel : public QSortFilterProxyModel { void refreshExpanded(QTreeView *tree) { tree->collapseAll(); - for(QModelIndex sourceIndex : expandList ) { + // The call to setExpanded causes expendList to be appended via + // the filterAcceptsRow overload. Since QList's implementation is an array, + // when the reserved space is exhausted, it must be reallocated. When this + // happens, iterators are likely to break. But because of this implemention, + // indexing is safe and efficient. + for (int i = 0; i < expandList.count(); i++) { + const QModelIndex& sourceIndex = expandList[i]; QModelIndex mappedIndex = mapFromSource( sourceIndex ); tree->setExpanded( mappedIndex, true ); }