QmlDesigner: Fix UB in QmlPreviewPlugin::getPreviewPlugin()

Each call to PluginManager::plugins() creates a new QVector object,
iterators are only comparable for iterators from the same vector.

It worked in practice because the underlying storage was the same
here as the QVector objects were only shallow copies.

Change-Id: I2e276535942bd949acf91e12873c7bdf9d5c34d6
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
hjk
2020-08-13 13:03:17 +02:00
committed by Eike Ziller
parent 5cece408de
commit fff3b41833

View File

@@ -158,13 +158,15 @@ void QmlPreviewPlugin::setLanguageLocale(const QString &locale)
QObject *QmlPreviewPlugin::getPreviewPlugin() QObject *QmlPreviewPlugin::getPreviewPlugin()
{ {
auto pluginIt = std::find_if(ExtensionSystem::PluginManager::plugins().begin(), const QVector<ExtensionSystem::PluginSpec *> specs = ExtensionSystem::PluginManager::plugins();
ExtensionSystem::PluginManager::plugins().end(),
auto pluginIt = std::find_if(specs.begin(),
specs.end(),
[](const ExtensionSystem::PluginSpec *p) { [](const ExtensionSystem::PluginSpec *p) {
return p->name() == "QmlPreview"; return p->name() == "QmlPreview";
}); });
if (pluginIt != ExtensionSystem::PluginManager::plugins().constEnd()) if (pluginIt != specs.end())
return (*pluginIt)->plugin(); return (*pluginIt)->plugin();
return nullptr; return nullptr;