PCExhumed: Handle integer overflow in PlotCourseToSprite()

This commit is contained in:
sirlemonhead 2020-06-17 20:27:10 +01:00 committed by Christoph Oelckers
parent 2a1ef00542
commit 80dd794550

View file

@ -677,7 +677,18 @@ int PlotCourseToSprite(int nSprite1, int nSprite2)
sprite[nSprite1].ang = GetMyAngle(x, y);
return ksqrt(y * y + x * x);
uint32_t x2 = klabs(x);
uint32_t y2 = klabs(y);
uint32_t diff = x2 * x2 + y2 * y2;
if (diff > INT_MAX)
{
OSD_Printf("%s %d: overflow\n", EDUKE32_FUNCTION, __LINE__);
diff = INT_MAX;
}
return ksqrt(diff);
}
int FindPlayer(int nSprite, int nDistance)