Fix integer overflow in wait command that would cause infinite loop in stock scripts

It was causing a rare infinite loop in anim/stand.scr where it waits for 9999999 if the actor is unarmed and medic
This commit is contained in:
smallmodel 2024-11-16 19:09:46 +01:00
parent 824cfd789c
commit b68bb4cee7
No known key found for this signature in database
GPG key ID: 9F2D623CEDF08512

View file

@ -2711,12 +2711,17 @@ void ScriptThread::EventDelayThrow(Event *ev)
void ScriptThread::EventWait(Event *ev)
{
Wait((int)roundf(ev->GetFloat(1) * 1000.0f));
float timeSeconds;
// Fixed in OPM
// Clamp to make sure to not overflow when converting to integer
timeSeconds = Q_clamp_float(ev->GetFloat(1), 0, 2000000);
Wait((int)roundf(timeSeconds * 1000));
}
void ScriptThread::EventWaitFrame(Event *ev)
{
Wait((int)roundf(level.frametime * 1000.0f));
Wait((int)roundf(level.frametime * 1000));
}
void ScriptThread::EventResume(Event *ev)