Skip to content

Commit

Permalink
[input] make some gamepad functions safer on Linux and FreeBSD
Browse files Browse the repository at this point in the history
  • Loading branch information
samhocevar committed Mar 20, 2024
1 parent 8b8764e commit 7ae2130
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
4 changes: 2 additions & 2 deletions Backends/System/Linux/Sources/kinc/backend/gamepad.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}

0 comments on commit 7ae2130

Please sign in to comment.