[rcore] Add gamepad >= 0 lower-bound guard to six sibling functions (#5938)

Commit 3edfe194 added a `gamepad >= 0` lower-bound check to
GetGamepadAxisCount() and GetGamepadName(), but six sibling functions
were left with only the upper-bound check (`gamepad < MAX_GAMEPADS`).
A negative signed int passes that check and triggers out-of-bounds
access on CORE.Input.Gamepad.ready[gamepad] and related arrays (UB in C).

Apply the same `(gamepad >= 0) &&` guard added in 3edfe194 to:
- IsGamepadAvailable
- IsGamepadButtonPressed
- IsGamepadButtonDown
- IsGamepadButtonReleased
- IsGamepadButtonUp
- GetGamepadAxisMovement
This commit is contained in:
greymoth
2026-06-28 04:06:49 +09:00
committed by GitHub
parent 3edfe19438
commit 67359073ca

View File

@@ -3926,7 +3926,7 @@ bool IsGamepadAvailable(int gamepad)
{
bool result = false;
if ((gamepad < MAX_GAMEPADS) && CORE.Input.Gamepad.ready[gamepad]) result = true;
if ((gamepad >= 0) && (gamepad < MAX_GAMEPADS) && CORE.Input.Gamepad.ready[gamepad]) result = true;
return result;
}
@@ -3946,7 +3946,7 @@ bool IsGamepadButtonPressed(int gamepad, int button)
{
bool pressed = false;
if ((gamepad < MAX_GAMEPADS) && CORE.Input.Gamepad.ready[gamepad] && (button < MAX_GAMEPAD_BUTTONS))
if ((gamepad >= 0) && (gamepad < MAX_GAMEPADS) && CORE.Input.Gamepad.ready[gamepad] && (button < MAX_GAMEPAD_BUTTONS))
{
if ((CORE.Input.Gamepad.previousButtonState[gamepad][button] == 0) && (CORE.Input.Gamepad.currentButtonState[gamepad][button] == 1)) pressed = true;
}
@@ -3959,7 +3959,7 @@ bool IsGamepadButtonDown(int gamepad, int button)
{
bool down = false;
if ((gamepad < MAX_GAMEPADS) && CORE.Input.Gamepad.ready[gamepad] && (button < MAX_GAMEPAD_BUTTONS))
if ((gamepad >= 0) && (gamepad < MAX_GAMEPADS) && CORE.Input.Gamepad.ready[gamepad] && (button < MAX_GAMEPAD_BUTTONS))
{
if (CORE.Input.Gamepad.currentButtonState[gamepad][button] == 1) down = true;
}
@@ -3972,7 +3972,7 @@ bool IsGamepadButtonReleased(int gamepad, int button)
{
bool released = false;
if ((gamepad < MAX_GAMEPADS) && CORE.Input.Gamepad.ready[gamepad] && (button < MAX_GAMEPAD_BUTTONS))
if ((gamepad >= 0) && (gamepad < MAX_GAMEPADS) && CORE.Input.Gamepad.ready[gamepad] && (button < MAX_GAMEPAD_BUTTONS))
{
if ((CORE.Input.Gamepad.previousButtonState[gamepad][button] == 1) && (CORE.Input.Gamepad.currentButtonState[gamepad][button] == 0)) released = true;
}
@@ -3985,7 +3985,7 @@ bool IsGamepadButtonUp(int gamepad, int button)
{
bool up = false;
if ((gamepad < MAX_GAMEPADS) && CORE.Input.Gamepad.ready[gamepad] && (button < MAX_GAMEPAD_BUTTONS))
if ((gamepad >= 0) && (gamepad < MAX_GAMEPADS) && CORE.Input.Gamepad.ready[gamepad] && (button < MAX_GAMEPAD_BUTTONS))
{
if (CORE.Input.Gamepad.currentButtonState[gamepad][button] == 0) up = true;
}
@@ -4015,7 +4015,7 @@ float GetGamepadAxisMovement(int gamepad, int axis)
{
float value = ((axis == GAMEPAD_AXIS_LEFT_TRIGGER) || (axis == GAMEPAD_AXIS_RIGHT_TRIGGER))? -1.0f : 0.0f;
if ((gamepad < MAX_GAMEPADS) && CORE.Input.Gamepad.ready[gamepad] && (axis < MAX_GAMEPAD_AXES))
if ((gamepad >= 0) && (gamepad < MAX_GAMEPADS) && CORE.Input.Gamepad.ready[gamepad] && (axis < MAX_GAMEPAD_AXES))
{
float movement = (value < 0.0f)? CORE.Input.Gamepad.axisState[gamepad][axis] : fabsf(CORE.Input.Gamepad.axisState[gamepad][axis]);