From e22487e8c44293e0d76405218a9a01e432ccf806 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 15 Jul 2026 05:36:17 +0000 Subject: [PATCH] Fix MSVC mul_overflows sign extension check --- src/util/mpz.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/util/mpz.cpp b/src/util/mpz.cpp index 026b88732..74430a130 100644 --- a/src/util/mpz.cpp +++ b/src/util/mpz.cpp @@ -20,6 +20,9 @@ Revision History: #include #include #include +#if defined(_MSC_VER) +#include +#endif #include "util/mpz.h" #include "util/buffer.h" #include "util/trace.h" @@ -36,7 +39,7 @@ static bool mul_overflows(int64_t a, int64_t b, int64_t & result) { __int64 high; result = _mul128(a, b, &high); // Overflow if high bits are not the sign extension of result - return high != (result >> 63); + return high != (result < 0 ? -1 : 0); #elif defined(_MSC_VER) // Extract magnitudes without ever evaluating -INT64_MIN. uint64_t x = a < 0 ? static_cast(-(a + 1)) + 1 : static_cast(a);