From cac28198382a97f873594ea77d17e90da79537f6 Mon Sep 17 00:00:00 2001 From: Tobias Hunger <tobias.hunger@nokia.com> Date: Wed, 8 Aug 2012 15:39:10 +0200 Subject: [PATCH] Fix crashes when no default profile is set * Handle 0 when calling createTarget to avoid the crashes in the first place * Do not try to create/add targets for 0 profiles to avoid creator writing a warning to the console * Fix possible crashes in debugger when no default profile is set. Task-number: QTCREATORBUG-7695 Change-Id: I9afc8e29c8b859ad078dad794ef5017168daac78 Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: Eike Ziller <eike.ziller@nokia.com> --- src/plugins/autotoolsprojectmanager/autotoolsproject.cpp | 5 +++-- src/plugins/cmakeprojectmanager/cmakeproject.cpp | 5 +++-- src/plugins/debugger/debuggerplugin.cpp | 3 ++- src/plugins/debugger/debuggerrunner.cpp | 2 +- src/plugins/genericprojectmanager/genericproject.cpp | 5 +++-- src/plugins/projectexplorer/project.cpp | 2 +- src/plugins/qmlprojectmanager/qmlproject.cpp | 5 +++-- 7 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/plugins/autotoolsprojectmanager/autotoolsproject.cpp b/src/plugins/autotoolsprojectmanager/autotoolsproject.cpp index 84c39c59140..ea88b555a93 100644 --- a/src/plugins/autotoolsprojectmanager/autotoolsproject.cpp +++ b/src/plugins/autotoolsprojectmanager/autotoolsproject.cpp @@ -158,8 +158,9 @@ bool AutotoolsProject::fromMap(const QVariantMap &map) // Load the project tree structure. evaluateBuildSystem(); - if (!activeTarget()) - addTarget(createTarget(ProfileManager::instance()->defaultProfile())); + Profile *defaultProfile = ProfileManager::instance()->defaultProfile(); + if (!activeTarget() && defaultProfile) + addTarget(createTarget(defaultProfile)); return true; } diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.cpp b/src/plugins/cmakeprojectmanager/cmakeproject.cpp index 0b148969ee9..aec60ba3ac3 100644 --- a/src/plugins/cmakeprojectmanager/cmakeproject.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeproject.cpp @@ -539,8 +539,9 @@ bool CMakeProject::fromMap(const QVariantMap &map) if (!Project::fromMap(map)) return false; - if (!activeTarget()) - addTarget(createTarget(ProfileManager::instance()->defaultProfile())); + Profile *defaultProfile = ProfileManager::instance()->defaultProfile(); + if (!activeTarget() && defaultProfile) + addTarget(createTarget(defaultProfile)); // We have a user file, but we could still be missing the cbp file // or simply run createXml with the saved settings diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp index 6cb43e7ebc3..9e92e768189 100644 --- a/src/plugins/debugger/debuggerplugin.cpp +++ b/src/plugins/debugger/debuggerplugin.cpp @@ -1317,7 +1317,8 @@ bool DebuggerPluginPrivate::parseArgument(QStringList::const_iterator &it, return false; } DebuggerStartParameters sp; - fillParameters(&sp, ProfileManager::instance()->defaultProfile()->id()); + Profile *defaultProfile = ProfileManager::instance()->defaultProfile(); + fillParameters(&sp, defaultProfile ? defaultProfile->id() : Core::Id()); qulonglong pid = it->toULongLong(); if (pid) { sp.startMode = AttachExternal; diff --git a/src/plugins/debugger/debuggerrunner.cpp b/src/plugins/debugger/debuggerrunner.cpp index 7e017a71cc0..65d0a1f1847 100644 --- a/src/plugins/debugger/debuggerrunner.cpp +++ b/src/plugins/debugger/debuggerrunner.cpp @@ -877,7 +877,7 @@ static DebuggerStartParameters localStartParameters(RunConfiguration *runConfigu Target *target = runConfiguration->target(); Profile *profile = target ? target->profile() : ProfileManager::instance()->defaultProfile(); - fillParameters(&sp, profile->id()); + fillParameters(&sp, profile ? profile->id() : Core::Id()); sp.environment = rc->environment(); sp.workingDirectory = rc->workingDirectory(); diff --git a/src/plugins/genericprojectmanager/genericproject.cpp b/src/plugins/genericprojectmanager/genericproject.cpp index caeead1f8ad..769e12f25ac 100644 --- a/src/plugins/genericprojectmanager/genericproject.cpp +++ b/src/plugins/genericprojectmanager/genericproject.cpp @@ -429,8 +429,9 @@ bool GenericProject::fromMap(const QVariantMap &map) if (!Project::fromMap(map)) return false; - if (!activeTarget()) - addTarget(createTarget(ProfileManager::instance()->defaultProfile())); + Profile *defaultProfile = ProfileManager::instance()->defaultProfile(); + if (!activeTarget() && defaultProfile) + addTarget(createTarget(defaultProfile)); // Sanity check: We need both a buildconfiguration and a runconfiguration! QList<Target *> targetList = targets(); diff --git a/src/plugins/projectexplorer/project.cpp b/src/plugins/projectexplorer/project.cpp index 37691035810..5f25724ee83 100644 --- a/src/plugins/projectexplorer/project.cpp +++ b/src/plugins/projectexplorer/project.cpp @@ -248,7 +248,7 @@ bool Project::supportsProfile(Profile *p) const Target *Project::createTarget(Profile *p) { - if (target(p)) + if (!p || target(p)) return 0; Target *t = new Target(this, p); diff --git a/src/plugins/qmlprojectmanager/qmlproject.cpp b/src/plugins/qmlprojectmanager/qmlproject.cpp index b0d19997a79..031878fe907 100644 --- a/src/plugins/qmlprojectmanager/qmlproject.cpp +++ b/src/plugins/qmlprojectmanager/qmlproject.cpp @@ -300,8 +300,9 @@ bool QmlProject::fromMap(const QVariantMap &map) if (!Project::fromMap(map)) return false; - if (!activeTarget()) - addTarget(createTarget(ProjectExplorer::ProfileManager::instance()->defaultProfile())); +ProjectExplorer::Profile *defaultProfile = ProjectExplorer::ProfileManager::instance()->defaultProfile(); + if (!activeTarget() && defaultProfile) + addTarget(createTarget(defaultProfile)); refresh(Everything); // FIXME workaround to guarantee that run/debug actions are enabled if a valid file exists -- GitLab