Fix #11005: Company value overflows (#11012)

* 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 <janisozaur@gmail.com>
This commit is contained in:
Thijs Versfelt 2020-03-27 13:25:16 +01:00 committed by GitHub
parent 47b6139546
commit 3613c660a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 2 deletions

View File

@ -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)

View File

@ -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;

View File

@ -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