Skip to content
Permalink
Browse files

expressions: fix modulo 0 crashes (fixes #12431)

  • Loading branch information
jef-n committed Mar 23, 2015
1 parent 28a2bf9 commit 9596f97db605421eabe6643a10f25db8a7747df9
Showing with 6 additions and 2 deletions.
  1. +6 −2 src/core/qgsexpression.cpp
@@ -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 ) )
@@ -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 ) );
}
@@ -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 ) );
}

0 comments on commit 9596f97

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