From 41aaa912e789db481a163b9d6eb8c49e43db97fc Mon Sep 17 00:00:00 2001 From: Elad <18193363+elad335@users.noreply.github.com> Date: Wed, 26 Nov 2025 15:34:38 +0200 Subject: [PATCH] Fixup ::narrow (#17756) Also fix negative signed to unsigned narrowing when source type is greater than destination. --- rpcs3/util/types.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rpcs3/util/types.hpp b/rpcs3/util/types.hpp index 80486a6e1a..4a2ef5baea 100644 --- a/rpcs3/util/types.hpp +++ b/rpcs3/util/types.hpp @@ -1000,7 +1000,7 @@ template requires (std::is_integral_v; // For unsigned/signed mismatch, create an "unsigned" compatible mask - constexpr auto from_mask = (is_from_signed && !is_to_signed) ? UnFrom{umax} >> 1 : UnFrom{umax}; + constexpr auto from_mask = (is_from_signed && !is_to_signed && sizeof(CommonFrom) <= sizeof(CommonTo)) ? UnFrom{umax} >> 1 : UnFrom{umax}; constexpr auto to_mask = (is_to_signed && !is_from_signed) ? UnTo{umax} >> 1 : UnTo{umax}; constexpr auto mask = static_cast(~(from_mask & to_mask)); @@ -1010,7 +1010,7 @@ template requires (std::is_integral_v(value) != static_cast(value)) [[unlikely]] + if (is_from_signed != is_to_signed ? !!(value & mask) : static_cast(static_cast(value)) != value) [[unlikely]] { fmt::raw_verify_error(src_loc, u8"Narrowing error", +value); }