[libcalamaresui] Avoid crash if modules-list is empty

If there are no modules at all before an exec: section is
reached (e.g. right now due to a bug in module-loading)
then the last() call would crash. Instead, use a nullptr
for the last-module-loaded.

While here, apply code-formatting.
This commit is contained in:
Adriaan de Groot 2022-02-07 15:52:18 +01:00
parent 932ab17c9a
commit 9f6f82405b

View File

@ -266,8 +266,8 @@ ModuleManager::loadModules()
// thisModule. We now need to enqueue jobs info into an EVS.
if ( currentAction == ModuleSystem::Action::Exec )
{
ExecutionViewStep* evs
= qobject_cast< ExecutionViewStep* >( Calamares::ViewManager::instance()->viewSteps().last() );
const auto steps = Calamares::ViewManager::instance()->viewSteps();
ExecutionViewStep* evs = steps.isEmpty() ? nullptr : qobject_cast< ExecutionViewStep* >( steps.last() );
if ( !evs ) // If the last step is not an EVS, we must create it.
{
evs = new ExecutionViewStep( ViewManager::instance() );
@ -281,7 +281,7 @@ ModuleManager::loadModules()
if ( !failedModules.isEmpty() )
{
ViewManager::instance()->onInitFailed( failedModules );
QTimer::singleShot( 10, [=]() { emit modulesFailed( failedModules ); } );
QTimer::singleShot( 10, [ = ]() { emit modulesFailed( failedModules ); } );
}
else
{
@ -337,9 +337,10 @@ ModuleManager::checkRequirements()
RequirementsChecker* rq = new RequirementsChecker( modules, m_requirementsModel, this );
connect( rq, &RequirementsChecker::done, rq, &RequirementsChecker::deleteLater );
connect( rq, &RequirementsChecker::done, this, [=]() {
this->requirementsComplete( m_requirementsModel->satisfiedMandatory() );
} );
connect( rq,
&RequirementsChecker::done,
this,
[ = ]() { this->requirementsComplete( m_requirementsModel->satisfiedMandatory() ); } );
QTimer::singleShot( 0, rq, &RequirementsChecker::run );
}