CompilationDatabasePM: Fix crash at loading project

If rootPath is empty, QtCreator will crash.

Fixes: QTCREATORBUG-26126
Change-Id: Iac0d29d84d7203c0ec2ac8f5e3035816f52d7cdc
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Cristian Adam
2021-09-01 14:59:17 +02:00
parent 04c36419f7
commit 830aeb8010

View File

@@ -440,8 +440,13 @@ Utils::FilePath CompilationDatabaseProject::rootPathFromSettings() const
#ifdef WITH_TESTS #ifdef WITH_TESTS
return Utils::FilePath::fromString(projectDirectory().fileName()); return Utils::FilePath::fromString(projectDirectory().fileName());
#else #else
return Utils::FilePath::fromString( auto rootPath = Utils::FilePath::fromString(
namedSettings(ProjectExplorer::Constants::PROJECT_ROOT_PATH_KEY).toString()); namedSettings(ProjectExplorer::Constants::PROJECT_ROOT_PATH_KEY).toString());
if (rootPath.isEmpty())
rootPath = Utils::FilePath::fromString(projectDirectory().fileName());
return rootPath;
#endif #endif
} }