summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorCharles Pigott <charlespigott@googlemail.com>2021-07-19 12:41:31 +0100
committerCharles Pigott <charlespigott@googlemail.com>2021-07-20 10:42:03 +0100
commit1e439979f7e359543fdb0c86238d51f64e161625 (patch)
tree86e8ff5dedf052df5157a24d9939c1a3449fbaf8 /src/core
parent9b0bb21f3b0cb9fb29ef7413900752eca5421b2a (diff)
downloadopenttd-1e439979f7e359543fdb0c86238d51f64e161625.tar.xz
Fix: OverflowSafeInt negation not handling INT64_MIN
INT64_MIN negated is above INT64_MAX, and would overflow. Instead, when negating INT64_MIN make it INT64_MAX. This does mean that -(-(INT64_MIN)) != INT64_MIN.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/overflowsafe_type.hpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/core/overflowsafe_type.hpp b/src/core/overflowsafe_type.hpp
index 2b1edeede..0a9df5920 100644
--- a/src/core/overflowsafe_type.hpp
+++ b/src/core/overflowsafe_type.hpp
@@ -34,7 +34,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.