Skip to content
Snippets Groups Projects
Unverified Commit e826286f authored by Haydn Trigg's avatar Haydn Trigg Committed by GitHub
Browse files

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
No related branches found
No related tags found
No related merge requests found
......@@ -179,7 +179,27 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, const TIntermTyped* right
case EbtDouble:
case EbtFloat:
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;
case EbtInt8:
if (rightUnionArray[i] == (signed char)0)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment