From 77d5e09576570cc9b04057a7f205f1369095064d Mon Sep 17 00:00:00 2001 From: Squall Leonhart Date: Sat, 28 Mar 2026 16:41:45 +1100 Subject: [PATCH] Fix bitwise operation for button state check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Classic buttons are shifted up by kHighestWiimote (20) before being stored, so they occupy bits 21–35 of the uint64 buttons variable. When the loop checks those bits with (1 << i), 1 is a plain 32-bit int. Shifting it by 32 or more is undefined behaviour — in practice on x86 it wraps modulo 32, so on x86 A (bit 32) → mask becomes 1 << 0 → becomes X B (bit 34) → mask becomes 1 << 2 → X Y (bit 33) → mask becomes 1 << 1 → X ZL (bit 35) → mask becomes 1 << 3 → also X X (bit 31) → mask is 1 << 31 → still within 32 bits → expectedly, X. change to 1ULL so it all works properly --- src/input/api/Wiimote/NativeWiimoteController.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/input/api/Wiimote/NativeWiimoteController.cpp b/src/input/api/Wiimote/NativeWiimoteController.cpp index 9aa56d9c..75025e09 100644 --- a/src/input/api/Wiimote/NativeWiimoteController.cpp +++ b/src/input/api/Wiimote/NativeWiimoteController.cpp @@ -232,7 +232,7 @@ ControllerState NativeWiimoteController::raw_state() for (int i = 0; i < std::numeric_limits::digits; i++) { // OR with base buttons - if((buttons & (1 << i))) + if((buttons & (1ULL << i))) result.buttons.SetButtonState(i, true); } result.axis = classic.left_axis;