Fix 6821c0e9: Incorrect use of __builtin_mul_overflow

Fixes: #164
This commit is contained in:
Jonathan G Rennison
2020-07-04 23:46:36 +01:00
parent e39a1d2b6e
commit bb8d2c3fe0

View File

@@ -95,7 +95,10 @@ public:
inline OverflowSafeInt& operator *= (const int factor) inline OverflowSafeInt& operator *= (const int factor)
{ {
#ifdef WITH_OVERFLOW_BUILTINS #ifdef WITH_OVERFLOW_BUILTINS
if (unlikely(__builtin_mul_overflow(this->m_value, factor, &this->m_value))) { T out;
if (likely(!__builtin_mul_overflow(this->m_value, factor, &out))) {
this->m_value = out;
} else {
this->m_value = ((this->m_value < 0) == (factor < 0)) ? T_MAX : T_MIN; this->m_value = ((this->m_value < 0) == (factor < 0)) ? T_MAX : T_MIN;
} }
#else #else