Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
expressions: fix modulo 0 crashes (fixes #12431)
(cherry picked from commit 9596f97)
  • Loading branch information
jef-n committed Mar 25, 2015
1 parent 3d3ccd0 commit 2e0cba5
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/core/qgsexpression.cpp
Expand Up @@ -2252,6 +2252,10 @@ QVariant QgsExpression::NodeBinaryOperator::eval( QgsExpression* parent, const Q
// both are integers - let's use integer arithmetics
int iL = getIntValue( vL, parent ); ENSURE_NO_EVAL_ERROR;
int iR = getIntValue( vR, parent ); ENSURE_NO_EVAL_ERROR;

if ( mOp == boMod && iR == 0 )
return QVariant();

return QVariant( computeInt( iL, iR ) );
}
else if ( isDateTimeSafe( vL ) && isIntervalSafe( vR ) )
Expand All @@ -2270,7 +2274,7 @@ QVariant QgsExpression::NodeBinaryOperator::eval( QgsExpression* parent, const Q
// general floating point arithmetic
double fL = getDoubleValue( vL, parent ); ENSURE_NO_EVAL_ERROR;
double fR = getDoubleValue( vR, parent ); ENSURE_NO_EVAL_ERROR;
if ( mOp == boDiv && fR == 0 )
if (( mOp == boDiv || mOp == boMod ) && fR == 0. )
return QVariant(); // silently handle division by zero and return NULL
return QVariant( computeDouble( fL, fR ) );
}
Expand All @@ -2280,7 +2284,7 @@ QVariant QgsExpression::NodeBinaryOperator::eval( QgsExpression* parent, const Q
//integer division
double fL = getDoubleValue( vL, parent ); ENSURE_NO_EVAL_ERROR;
double fR = getDoubleValue( vR, parent ); ENSURE_NO_EVAL_ERROR;
if ( fR == 0 )
if ( fR == 0. )
return QVariant(); // silently handle division by zero and return NULL
return QVariant( qFloor( fL / fR ) );
}
Expand Down

0 comments on commit 2e0cba5

Please sign in to comment.