From e3253cddf9cb3a4a987775f8e20cbd4ffb46236e Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 16 Oct 2026 17:45:26 +0200 Subject: [PATCH] Fix undefined behavior in portable smulh --- src/instructions_portable.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/instructions_portable.cpp b/src/instructions_portable.cpp index d7467271..5d5921fe 100644 --- a/src/instructions_portable.cpp +++ b/src/instructions_portable.cpp @@ -123,10 +123,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef HAVE_SMULH int64_t smulh(int64_t a, int64_t b) { - int64_t hi = mulh(a, b); + uint64_t hi = mulh(a, b); if (a < 0LL) hi -= b; if (b < 0LL) hi -= a; - return hi; + return unsigned64ToSigned2sCompl(hi); } #define HAVE_SMULH #endif