diff options
author | Charles Pigott <charlespigott@googlemail.com> | 2021-07-19 12:41:31 +0100 |
---|---|---|
committer | Charles Pigott <charlespigott@googlemail.com> | 2021-07-20 10:42:03 +0100 |
commit | 1e439979f7e359543fdb0c86238d51f64e161625 (patch) | |
tree | 86e8ff5dedf052df5157a24d9939c1a3449fbaf8 | |
parent | 9b0bb21f3b0cb9fb29ef7413900752eca5421b2a (diff) | |
download | openttd-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.
-rw-r--r-- | src/core/overflowsafe_type.hpp | 2 |
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. |