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.
pull/332/head
Charles Pigott 3 years ago
parent 9b0bb21f3b
commit 1e439979f7

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

Loading…
Cancel
Save