From cf92ba84ef315224f8fbcbb314f315de62b4ace7 Mon Sep 17 00:00:00 2001 From: Jannik Vogel Date: Mon, 16 May 2016 21:33:05 +0200 Subject: [PATCH] UXTB16: Avoid undefined behaviour (shift past width) --- src/core/arm/dyncom/arm_dyncom_interpreter.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/core/arm/dyncom/arm_dyncom_interpreter.cpp b/src/core/arm/dyncom/arm_dyncom_interpreter.cpp index 8d4b26815..a950259ea 100644 --- a/src/core/arm/dyncom/arm_dyncom_interpreter.cpp +++ b/src/core/arm/dyncom/arm_dyncom_interpreter.cpp @@ -6854,18 +6854,20 @@ unsigned InterpreterMainLoop(ARMul_State* cpu) { uxtab_inst* const inst_cream = (uxtab_inst*)inst_base->component; const u8 rn_idx = inst_cream->Rn; - const u32 rm_val = RM; const u32 rotation = inst_cream->rotate * 8; - const u32 rotated_rm = ((rm_val << (32 - rotation)) | (rm_val >> rotation)); + u32 rm_val = RM; + + if (rotation) + rm_val = ((rm_val << (32 - rotation)) | (rm_val >> rotation)); // UXTB16, otherwise UXTAB16 if (rn_idx == 15) { - RD = rotated_rm & 0x00FF00FF; + RD = rm_val & 0x00FF00FF; } else { const u32 rn_val = RN; - const u8 lo_rotated = (rotated_rm & 0xFF); + const u8 lo_rotated = (rm_val & 0xFF); const u16 lo_result = (rn_val & 0xFFFF) + (u16)lo_rotated; - const u8 hi_rotated = (rotated_rm >> 16) & 0xFF; + const u8 hi_rotated = (rm_val >> 16) & 0xFF; const u16 hi_result = (rn_val >> 16) + (u16)hi_rotated; RD = ((hi_result << 16) | (lo_result & 0xFFFF));