From 19a13932a45860dec80f410a886408c481114c64 Mon Sep 17 00:00:00 2001 From: Cristian Adam Date: Mon, 7 Apr 2025 11:01:21 +0200 Subject: [PATCH] CMakePM: Fix crash when adding files to target having zero arguments Qt Creator restores a backup of a project's structure when a CMake configuration fails. If a user removes all arguments from a function defining a target, configure CMake and have the backup restored can lead to a state where the backup target exists in the project structure. Then when trying to add files to this target Qt Creator crashes. Fixes: QTCREATORBUG-32745 Change-Id: I9db9b54ae883f6c5b40da623a9984e9c33195d30 Reviewed-by: Eike Ziller --- src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp b/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp index 108a94716ec..092d5639992 100644 --- a/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp +++ b/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp @@ -697,6 +697,11 @@ bool CMakeBuildSystem::addSrcFiles(Node *context, const FilePaths &filePaths, Fi << "could not be found at" << targetDefinitionLine; return false; } + if (function->Arguments().size() == 0) { + qCCritical(cmakeBuildSystemLog) << "Function that defined the target" << targetName + << "has zero arguments."; + return false; + } const bool haveGlobbing = isGlobbingFunction(*cmakeListFile, *function); n->setVisibleAfterAddFileAction(!haveGlobbing);