ProjectExplorer: Prevent out of range access on recent projects list

ProjectExplorerPlugin::recentProjects() filters out non-existent files.
Because files could at any time be removed/renamed, we cannot presume a
certain, constant length of the list when calling recentProjects() a
second time.

Fixes: QTCREATORBUG-27399
Change-Id: I3f09830896b308e251881c855abb552b6022695f
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Alessandro Portale
2022-04-27 15:09:32 +02:00
parent a984e9c097
commit 1811b381eb

View File

@@ -83,7 +83,10 @@ int ProjectModel::rowCount(const QModelIndex &) const
QVariant ProjectModel::data(const QModelIndex &index, int role) const
{
QPair<QString,QString> data = ProjectExplorerPlugin::recentProjects().at(index.row());
const QList<QPair<QString, QString> > recentProjects = ProjectExplorerPlugin::recentProjects();
if (recentProjects.count() <= index.row())
return {};
QPair<QString, QString> data = recentProjects.at(index.row());
switch (role) {
case Qt::DisplayRole:
return data.second;