mirror of https://github.com/OpenTTD/OpenTTD.git
Fix #10009: bad overflow protection when taking out loans
This commit is contained in:
parent
2355882ec1
commit
1ed0b35520
|
@ -176,6 +176,9 @@ public:
|
|||
inline constexpr bool operator <= (const int other) const { return !(*this > other); }
|
||||
|
||||
inline constexpr operator T () const { return this->m_value; }
|
||||
|
||||
static inline constexpr OverflowSafeInt<T> max() { return T_MAX; }
|
||||
static inline constexpr OverflowSafeInt<T> min() { return T_MIN; }
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -60,8 +60,10 @@ CommandCost CmdIncreaseLoan(DoCommandFlag flags, LoanCommand cmd, Money amount)
|
|||
break;
|
||||
}
|
||||
|
||||
/* Overflow protection */
|
||||
if (c->money + c->current_loan + loan < c->money) return CMD_ERROR;
|
||||
/* In case adding the loan triggers the overflow protection of Money,
|
||||
* we would essentially be losing money as taking and repaying the loan
|
||||
* immediately would not get us back to the same bank balance anymore. */
|
||||
if (c->money > Money::max() - loan) return CMD_ERROR;
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
c->money += loan;
|
||||
|
|
Loading…
Reference in New Issue