Skip to content

Commit d008d31

Browse files
committedAug 16, 2016
Fix potential crash when using default expression parameters
1 parent e3f0d3d commit d008d31

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed
 

‎src/core/qgsexpression.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2514,14 +2514,14 @@ static QVariant fcnShortestLine( const QVariantList& values, const QgsExpression
25142514

25152515
static QVariant fcnRound( const QVariantList& values, const QgsExpressionContext *, QgsExpression* parent )
25162516
{
2517-
if ( values.length() == 2 )
2517+
if ( values.length() == 2 && values.at( 1 ).toInt() != 0 )
25182518
{
25192519
double number = getDoubleValue( values.at( 0 ), parent );
25202520
double scaler = pow( 10.0, getIntValue( values.at( 1 ), parent ) );
25212521
return QVariant( qRound( number * scaler ) / scaler );
25222522
}
25232523

2524-
if ( values.length() == 1 )
2524+
if ( values.length() >= 1 )
25252525
{
25262526
double number = getIntValue( values.at( 0 ), parent );
25272527
return QVariant( qRound( number ) );

‎src/core/qgsexpression.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -951,9 +951,9 @@ class CORE_EXPORT QgsExpression
951951
NodeFunction( int fnIndex, NodeList* args ) : mFnIndex( fnIndex )
952952
{
953953
const ParameterList& functionParams = Functions()[mFnIndex]->parameters();
954-
if ( !args || !args->hasNamedNodes() || functionParams.isEmpty() )
954+
if ( !args || functionParams.isEmpty() )
955955
{
956-
// no named parameters, or function does not support them
956+
// no parameters, or function does not support them
957957
mArgs = args;
958958
}
959959
else
@@ -962,7 +962,7 @@ class CORE_EXPORT QgsExpression
962962

963963
int idx = 0;
964964
//first loop through unnamed arguments
965-
while ( args->names().at( idx ).isEmpty() )
965+
while ( idx < args->names().size() && args->names().at( idx ).isEmpty() )
966966
{
967967
mArgs->append( args->list().at( idx )->clone() );
968968
idx++;

0 commit comments

Comments
 (0)
Please sign in to comment.