Cap var2CTotal so it does not overflow

This commit is contained in:
Michał Janiszewski 2016-12-30 02:16:13 +01:00 committed by Ted John
parent b1ab5c96e5
commit 99a662fc5f
2 changed files with 9 additions and 2 deletions

View File

@ -55,7 +55,7 @@ extern "C" {
// This define specifies which version of network stream current build uses.
// It is used for making sure only compatible builds get connected, even within
// single OpenRCT2 version.
#define NETWORK_STREAM_VERSION "25"
#define NETWORK_STREAM_VERSION "26"
#define NETWORK_STREAM_ID OPENRCT2_VERSION "-" NETWORK_STREAM_VERSION
#ifdef __cplusplus

View File

@ -475,7 +475,14 @@ int cable_lift_update_track_motion(rct_vehicle *cableLift)
rct_vehicle* vehicle = GET_VEHICLE(spriteId);
vehicleCount++;
frictionTotal += vehicle->friction;
var2CTotal += vehicle->acceleration;
// Prevent over/underflow in var2CTotal
if ((INT32_MAX - abs(vehicle->acceleration)) < abs(var2CTotal) &&
(var2CTotal < 0) == (vehicle->acceleration < 0))
{
var2CTotal = (var2CTotal < 0) ? INT32_MIN : INT32_MAX ;
} else {
var2CTotal += vehicle->acceleration;
}
spriteId = vehicle->next_vehicle_on_train;
}