Skip to content

Commit

Permalink
Fix potential crash when using default expression parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 16, 2016
1 parent e3f0d3d commit d008d31
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/core/qgsexpression.cpp
Expand Up @@ -2514,14 +2514,14 @@ static QVariant fcnShortestLine( const QVariantList& values, const QgsExpression

static QVariant fcnRound( const QVariantList& values, const QgsExpressionContext *, QgsExpression* parent )
{
if ( values.length() == 2 )
if ( values.length() == 2 && values.at( 1 ).toInt() != 0 )
{
double number = getDoubleValue( values.at( 0 ), parent );
double scaler = pow( 10.0, getIntValue( values.at( 1 ), parent ) );
return QVariant( qRound( number * scaler ) / scaler );
}

if ( values.length() == 1 )
if ( values.length() >= 1 )
{
double number = getIntValue( values.at( 0 ), parent );
return QVariant( qRound( number ) );
Expand Down
6 changes: 3 additions & 3 deletions src/core/qgsexpression.h
Expand Up @@ -951,9 +951,9 @@ class CORE_EXPORT QgsExpression
NodeFunction( int fnIndex, NodeList* args ) : mFnIndex( fnIndex )
{
const ParameterList& functionParams = Functions()[mFnIndex]->parameters();
if ( !args || !args->hasNamedNodes() || functionParams.isEmpty() )
if ( !args || functionParams.isEmpty() )
{
// no named parameters, or function does not support them
// no parameters, or function does not support them
mArgs = args;
}
else
Expand All @@ -962,7 +962,7 @@ class CORE_EXPORT QgsExpression

int idx = 0;
//first loop through unnamed arguments
while ( args->names().at( idx ).isEmpty() )
while ( idx < args->names().size() && args->names().at( idx ).isEmpty() )
{
mArgs->append( args->list().at( idx )->clone() );
idx++;
Expand Down

0 comments on commit d008d31

Please sign in to comment.