diff --git a/src/joystick.c b/src/joystick.c index 682ba4b0..d7f98758 100644 --- a/src/joystick.c +++ b/src/joystick.c @@ -47,6 +47,12 @@ GLFWAPI int glfwGetJoystickParam(int joy, int param) return 0; } + if (joy < 0 || joy > GLFW_JOYSTICK_LAST) + { + _glfwSetError(GLFW_INVALID_ENUM, NULL); + return 0; + } + return _glfwPlatformGetJoystickParam(joy, param); } @@ -65,6 +71,18 @@ GLFWAPI int glfwGetJoystickPos(int joy, float* pos, int numaxes) return 0; } + if (joy < 0 || joy > GLFW_JOYSTICK_LAST) + { + _glfwSetError(GLFW_INVALID_ENUM, NULL); + return 0; + } + + if (pos == NULL || numaxes < 0) + { + _glfwSetError(GLFW_INVALID_VALUE, NULL); + return 0; + } + // Clear positions for (i = 0; i < numaxes; i++) pos[i] = 0.0f; @@ -89,6 +107,18 @@ GLFWAPI int glfwGetJoystickButtons(int joy, return 0; } + if (joy < 0 || joy > GLFW_JOYSTICK_LAST) + { + _glfwSetError(GLFW_INVALID_ENUM, NULL); + return 0; + } + + if (buttons == NULL || numbuttons < 0) + { + _glfwSetError(GLFW_INVALID_VALUE, NULL); + return 0; + } + // Clear button states for (i = 0; i < numbuttons; i++) buttons[i] = GLFW_RELEASE; diff --git a/src/x11_joystick.c b/src/x11_joystick.c index e54a7c02..523a4b3d 100644 --- a/src/x11_joystick.c +++ b/src/x11_joystick.c @@ -236,7 +236,7 @@ int _glfwPlatformGetJoystickParam(int joy, int param) return _glfwLibrary.X11.joystick[joy].numButtons; default: - break; + _glfwSetError(GLFW_INVALID_ENUM, NULL); } return 0;