Unverified Commit e826286f by Haydn Trigg Committed by GitHub

Constant.cpp Floating point divide by zero

Constant.cpp will throw a floating point divide by zero if floating point exceptions are enabled in Win32 causing the program to crash. This fix manually checks the right-hand argument of the division and sets appropriate Infinity, Negative Infinity, or NAN as if the floating point exceptions were disabled.
parent 0b964b3c
...@@ -179,7 +179,27 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, const TIntermTyped* right ...@@ -179,7 +179,27 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, const TIntermTyped* right
case EbtDouble: case EbtDouble:
case EbtFloat: case EbtFloat:
case EbtFloat16: case EbtFloat16:
newConstArray[i].setDConst(leftUnionArray[i].getDConst() / rightUnionArray[i].getDConst()); {
auto right = rightUnionArray[i].getDConst();
auto left = leftUnionArray[i].getDConst();
if (right)
{
newConstArray[i].setDConst(left / right);
}
else if (left > 0)
{
newConstArray[i].setDConst((double)INFINITY);
}
else if (left < 0)
{
newConstArray[i].setDConst((double)-INFINITY);
}
else
{
newConstArray[i].setDConst((double)NAN);
}
}
break; break;
case EbtInt8: case EbtInt8:
if (rightUnionArray[i] == (signed char)0) if (rightUnionArray[i] == (signed char)0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment