From 7ae21301338b44a28a16518088bb5028b191b069 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Wed, 20 Mar 2024 17:21:40 +0100 Subject: [PATCH] [input] make some gamepad functions safer on Linux and FreeBSD --- .../System/FreeBSD/Sources/kinc/backend/input/gamepad.cpp | 4 ++-- Backends/System/Linux/Sources/kinc/backend/gamepad.c.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Backends/System/FreeBSD/Sources/kinc/backend/input/gamepad.cpp b/Backends/System/FreeBSD/Sources/kinc/backend/input/gamepad.cpp index 31c27275f..3bb01ec41 100644 --- a/Backends/System/FreeBSD/Sources/kinc/backend/input/gamepad.cpp +++ b/Backends/System/FreeBSD/Sources/kinc/backend/input/gamepad.cpp @@ -118,11 +118,11 @@ const char *kinc_gamepad_vendor(int gamepad) { } const char *kinc_gamepad_product_name(int gamepad) { - return gamepads[gamepad].name; + return gamepad >= 0 && gamepad < KINC_GAMEPAD_MAX_COUNT ? gamepads[gamepad].name : ""; } bool kinc_gamepad_connected(int gamepad) { - return gamepads[gamepad].connected; + return gamepad >= 0 && gamepad < KINC_GAMEPAD_MAX_COUNT && gamepads[gamepad].connected; } void kinc_gamepad_rumble(int gamepad, float left, float right) {} \ No newline at end of file diff --git a/Backends/System/Linux/Sources/kinc/backend/gamepad.c.h b/Backends/System/Linux/Sources/kinc/backend/gamepad.c.h index 03d671133..74b3dde94 100644 --- a/Backends/System/Linux/Sources/kinc/backend/gamepad.c.h +++ b/Backends/System/Linux/Sources/kinc/backend/gamepad.c.h @@ -188,11 +188,11 @@ const char *kinc_gamepad_vendor(int gamepad) { } const char *kinc_gamepad_product_name(int gamepad) { - return gamepads[gamepad].name; + return gamepad >= 0 && gamepad < KINC_GAMEPAD_MAX_COUNT ? gamepads[gamepad].name : ""; } bool kinc_gamepad_connected(int gamepad) { - return gamepads[gamepad].connected; + return gamepad >= 0 && gamepad < KINC_GAMEPAD_MAX_COUNT && gamepads[gamepad].connected; } void kinc_gamepad_rumble(int gamepad, float left, float right) {}