Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Fix potential crash when preparing with_variable and no context is set
- Loading branch information
Showing
with
13 additions
and
3 deletions.
-
+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; |
|
|
} |
|
|