1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-23 10:48:51 -05:00

Added joystick API error checks for shared and Linux code.

This commit is contained in:
Camilla Berglund 2012-08-26 18:28:30 +02:00
parent c28fb4ca0c
commit 1839c1c73d
2 changed files with 31 additions and 1 deletions

View File

@ -47,6 +47,12 @@ GLFWAPI int glfwGetJoystickParam(int joy, int param)
return 0; return 0;
} }
if (joy < 0 || joy > GLFW_JOYSTICK_LAST)
{
_glfwSetError(GLFW_INVALID_ENUM, NULL);
return 0;
}
return _glfwPlatformGetJoystickParam(joy, param); return _glfwPlatformGetJoystickParam(joy, param);
} }
@ -65,6 +71,18 @@ GLFWAPI int glfwGetJoystickPos(int joy, float* pos, int numaxes)
return 0; 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 // Clear positions
for (i = 0; i < numaxes; i++) for (i = 0; i < numaxes; i++)
pos[i] = 0.0f; pos[i] = 0.0f;
@ -89,6 +107,18 @@ GLFWAPI int glfwGetJoystickButtons(int joy,
return 0; 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 // Clear button states
for (i = 0; i < numbuttons; i++) for (i = 0; i < numbuttons; i++)
buttons[i] = GLFW_RELEASE; buttons[i] = GLFW_RELEASE;

View File

@ -236,7 +236,7 @@ int _glfwPlatformGetJoystickParam(int joy, int param)
return _glfwLibrary.X11.joystick[joy].numButtons; return _glfwLibrary.X11.joystick[joy].numButtons;
default: default:
break; _glfwSetError(GLFW_INVALID_ENUM, NULL);
} }
return 0; return 0;