From 838847038fd90edf16931fe45a17aa61f9ec5b6f Mon Sep 17 00:00:00 2001 From: "Andon M. Coleman" Date: Mon, 7 Aug 2023 15:25:05 -0400 Subject: [PATCH] Properly handle HID events when processing WM_INPUT Failure to handle the case where WM_INPUT indicates an HID event leaves inp uninitialized and causes the RIM_TYPEMOUSE case to execute when it should not. --- src/video/windows/SDL_windowsevents.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c index 5ab0e68fb313f..5aad87d0ec29c 100644 --- a/src/video/windows/SDL_windowsevents.c +++ b/src/video/windows/SDL_windowsevents.c @@ -877,7 +877,14 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) break; } - GetRawInputData(hRawInput, RID_INPUT, &inp, &size, sizeof(RAWINPUTHEADER)); + /* If this is an HID event, it will return -1 with an Insufficient Buffer error. + + Rather than call this twice to retrieve the header and then determine the type, + expect it to fail and ignore the error. + */ + if ((int)GetRawInputData(hRawInput, RID_INPUT, &inp, &size, sizeof(RAWINPUTHEADER)) < 0) { + break; + } /* Mouse data (ignoring synthetic mouse events generated for touchscreens) */ if (inp.header.dwType == RIM_TYPEMOUSE) {