From 609f37cef953b2e95ed21216eaa51928aa688d1e Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Fri, 2 Oct 2020 17:50:20 +0100 Subject: [PATCH] Fix OverflowSafeInt negation not handling INT64_MIN See: https://github.com/OpenTTD/OpenTTD/issues/8284 --- src/core/overflowsafe_type.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/overflowsafe_type.hpp b/src/core/overflowsafe_type.hpp index 25fa715572..19cfd2bfb5 100644 --- a/src/core/overflowsafe_type.hpp +++ b/src/core/overflowsafe_type.hpp @@ -36,7 +36,7 @@ public: inline OverflowSafeInt& operator = (const OverflowSafeInt& other) { this->m_value = other.m_value; return *this; } - inline OverflowSafeInt operator - () const { return OverflowSafeInt(-this->m_value); } + inline OverflowSafeInt operator - () const { return OverflowSafeInt(this->m_value == T_MIN ? T_MAX : -this->m_value); } /** * Safe implementation of addition.