diff --git a/src/m_fixed.c b/src/m_fixed.c index d7aa13254..3bab22815 100644 --- a/src/m_fixed.c +++ b/src/m_fixed.c @@ -62,6 +62,9 @@ FUNCMATH fixed_t FixedHypot(fixed_t x, fixed_t y) angle_t angle; fixed_t dist; + I_Assert(x != INT32_MIN); + I_Assert(y != INT32_MIN); + x = abs(x); y = abs(y); @@ -77,6 +80,10 @@ FUNCMATH fixed_t FixedHypot(fixed_t x, fixed_t y) if (!y) return x; + // prevent underflow + if (y == INT32_MIN) + return INT32_MAX; + angle = (tantoangle[FixedDiv(y, x)>>DBITS] + ANGLE_90) >> ANGLETOFINESHIFT; // use as cosine