Skip to content
Permalink
Browse files

Fix potential crash when preparing with_variable and no context is set

  • Loading branch information
nyalldawson committed Aug 23, 2018
1 parent 6196fd3 commit c7eafc63c229c4febb60873c3df66406edc868fd
Showing with 13 additions and 3 deletions.
  1. +13 −3 src/core/expression/qgsexpressionfunction.cpp
@@ -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;
}

0 comments on commit c7eafc6

Please sign in to comment.
You can’t perform that action at this time.