Browse Source

cmake-gui: Fix crash when built with Qt 5.14 or later

In commit d7679f6427 (QCMakeCacheView: use non-deprecated List and Set
constructions, 2020-06-10, v3.18.0-rc2~13^2) the conversion of the
`this->properties()` value to QSet is incorrect for Qt 5.14+.  The
problem is that `this->properties()` returns by value, so the range
`this->properties().begin(), this->properties().end()` provides
iterators to two different instances.  Use an intermediate temporary
copy of the value to get a consistent iterator range.

Fixes: #20981
Brad King 5 years ago
parent
commit
af6cf586f6
1 changed files with 3 additions and 2 deletions
  1. 3 2
      Source/QtDialog/QCMakeCacheView.cxx

+ 3 - 2
Source/QtDialog/QCMakeCacheView.cxx

@@ -226,8 +226,9 @@ void QCMakeCacheModel::setProperties(const QCMakePropertyList& props)
 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
     QSet<QCMakeProperty> oldProps = this->properties().toSet();
     QSet<QCMakeProperty> oldProps = this->properties().toSet();
 #else
 #else
-    QSet<QCMakeProperty> oldProps = QSet<QCMakeProperty>(
-      this->properties().begin(), this->properties().end());
+    QCMakePropertyList const& oldPropsList = this->properties();
+    QSet<QCMakeProperty> oldProps =
+      QSet<QCMakeProperty>(oldPropsList.begin(), oldPropsList.end());
 #endif
 #endif
     oldProps.intersect(newProps);
     oldProps.intersect(newProps);
     newProps.subtract(oldProps);
     newProps.subtract(oldProps);