Protect against integer overflow when subtracting with action timer API

develop
Tachytaenius 2022-11-23 14:06:26 +00:00
parent 6148307e9b
commit cc40b80456
1 changed files with 6 additions and 1 deletions

@ -2012,7 +2012,12 @@ void subtractActionTimerCore(df::unit_action *action, int32_t amount)
{
int32_t *timer = getActionTimerPointer(action);
if (timer != nullptr && *timer > 0) {
*timer = max(*timer - amount, 1);
double value = *timer;
value = max(value - amount, 1.0);
if (value > INT32_MAX) {
value = INT32_MAX;
}
*timer = value;
}
}