Skip to content

Commit

Permalink
Fix potential crash when preparing with_variable and no context is set
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 23, 2018
1 parent 6196fd3 commit c7eafc6
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/core/expression/qgsexpressionfunction.cpp
Expand Up @@ -4941,9 +4941,19 @@ bool QgsWithVariableExpressionFunction::prepare( const QgsExpressionNodeFunction
QVariant name = args->at( 0 )->prepare( parent, context );
QVariant value = args->at( 1 )->prepare( parent, context );

appendTemporaryVariable( context, name.toString(), value );
args->at( 2 )->prepare( parent, context );
popTemporaryVariable( context );
QgsExpressionContext *updatedContext = const_cast<QgsExpressionContext *>( context );
std::unique_ptr< QgsExpressionContext > tempContext;
if ( !context )
{
tempContext = qgis::make_unique< QgsExpressionContext >();
updatedContext = tempContext.get();
}

appendTemporaryVariable( updatedContext, name.toString(), value );
args->at( 2 )->prepare( parent, updatedContext );

if ( context )
popTemporaryVariable( updatedContext );

return true;
}
Expand Down

0 comments on commit c7eafc6

Please sign in to comment.