From 3613c660a0b4d2bc7d81329424f525eac7e3c7e3 Mon Sep 17 00:00:00 2001 From: Thijs Versfelt <40113382+thversfelt@users.noreply.github.com> Date: Fri, 27 Mar 2020 13:25:16 +0100 Subject: [PATCH] Fix #11005: Company value overflows (#11012) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Clamp park value to prevent integer overflow. * Replace casting with built-in clamping. * Add changlog entry for #11005. * Modify casting to prevent skewed company value. * Increment network version Co-authored-by: MichaƂ Janiszewski --- distribution/changelog.txt | 1 + src/openrct2/network/Network.cpp | 2 +- src/openrct2/world/Park.cpp | 8 +++++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index a7bb3ebd73..3ef5757088 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -4,6 +4,7 @@ - Fix: [#475] Water sides drawn incorrectly (original bug). - Fix: [#6123, #7907, #9472, #11028] Cannot build some track designs with 4 stations (original bug). - Fix: [#7094] Back wall edge texture in water missing. +- Fix: [#11005] Company value overflows. - Fix: [#11027] Third color on walls becomes black when saving. 0.2.5 (2020-03-24) diff --git a/src/openrct2/network/Network.cpp b/src/openrct2/network/Network.cpp index 0ebbbfaed6..f3f360e540 100644 --- a/src/openrct2/network/Network.cpp +++ b/src/openrct2/network/Network.cpp @@ -31,7 +31,7 @@ // This string 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 "1" +#define NETWORK_STREAM_VERSION "2" #define NETWORK_STREAM_ID OPENRCT2_VERSION "-" NETWORK_STREAM_VERSION static Peep* _pickup_peep = nullptr; diff --git a/src/openrct2/world/Park.cpp b/src/openrct2/world/Park.cpp index 3ab8b011e6..e9354ca34e 100644 --- a/src/openrct2/world/Park.cpp +++ b/src/openrct2/world/Park.cpp @@ -33,6 +33,7 @@ #include "../ride/RideData.h" #include "../ride/ShopItem.h" #include "../scenario/Scenario.h" +#include "../util/Util.h" #include "../windows/Intent.h" #include "Entrance.h" #include "Map.h" @@ -516,7 +517,12 @@ money32 Park::CalculateRideValue(const Ride* ride) const money32 Park::CalculateCompanyValue() const { - return finance_get_current_cash() + gParkValue - gBankLoan; + money32 result = gParkValue - gBankLoan; + + // Clamp addition to prevent overflow + result = add_clamp_money32(result, finance_get_current_cash()); + + return result; } money16 Park::CalculateTotalRideValueForMoney() const