Fix division by zero when wrapping lateness_counter with 0 timetable duration

This commit is contained in:
Jonathan G Rennison
2024-01-21 02:07:32 +00:00
parent 74b5511dbc
commit f247451c61

View File

@@ -1044,7 +1044,11 @@ void UpdateVehicleTimetable(Vehicle *v, bool travelling)
if (v->lateness_counter > (int)timetabled) { if (v->lateness_counter > (int)timetabled) {
Ticks cycle = v->orders->GetTimetableTotalDuration(); Ticks cycle = v->orders->GetTimetableTotalDuration();
if (cycle != INVALID_TICKS && v->lateness_counter > cycle) { if (cycle != INVALID_TICKS && v->lateness_counter > cycle) {
v->lateness_counter %= cycle; if (cycle == 0) {
v->lateness_counter = 0;
} else {
v->lateness_counter %= cycle;
}
} }
} }