From 17e62acd682b95bf176c2fa536de6cd857a20a4f Mon Sep 17 00:00:00 2001 From: Gabriel Ferreira Date: Wed, 11 Sep 2024 12:30:52 +0200 Subject: [PATCH] core: Prevent signed integer overflow of minimum value --- src/core/model/int64x64-128.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/model/int64x64-128.h b/src/core/model/int64x64-128.h index 0f80a0ced..28d00e453 100644 --- a/src/core/model/int64x64-128.h +++ b/src/core/model/int64x64-128.h @@ -217,7 +217,8 @@ class int64x64_t inline double GetDouble() const { const bool negative = _v < 0; - const uint128_t value = negative ? -_v : _v; + const int128_t vTemp = _v + (_v == std::numeric_limits::min()); + const uint128_t value = negative ? -vTemp : vTemp; const long double fhi = value >> 64; const long double flo = (value & HP_MASK_LO) / HP_MAX_64; long double retval = fhi;