DriverStation: fix error checking for GetXXXAxis and GetXXXPov (#1469)

Fixes #1436
This commit is contained in:
Dustin Spicuzza
2018-12-07 01:31:14 -05:00
committed by Peter Johnson
parent dcbf02a1ec
commit b64dfacff3
2 changed files with 5 additions and 5 deletions

View File

@@ -160,7 +160,7 @@ bool DriverStation::GetStickButtonReleased(int stick, int button) {
wpi_setWPIError(BadJoystickIndex);
return false;
}
if (button == 0) {
if (button <= 0) {
ReportJoystickUnpluggedError(
"ERROR: Button indexes begin at 1 in WPILib for C++ and Java");
return false;
@@ -189,7 +189,7 @@ double DriverStation::GetStickAxis(int stick, int axis) {
wpi_setWPIError(BadJoystickIndex);
return 0.0;
}
if (axis >= HAL_kMaxJoystickAxes) {
if (axis < 0 || axis >= HAL_kMaxJoystickAxes) {
wpi_setWPIError(BadJoystickAxis);
return 0.0;
}
@@ -211,7 +211,7 @@ int DriverStation::GetStickPOV(int stick, int pov) {
wpi_setWPIError(BadJoystickIndex);
return -1;
}
if (pov >= HAL_kMaxJoystickPOVs) {
if (pov < 0 || pov >= HAL_kMaxJoystickPOVs) {
wpi_setWPIError(BadJoystickAxis);
return -1;
}

View File

@@ -420,7 +420,7 @@ public class DriverStation {
if (stick < 0 || stick >= kJoystickPorts) {
throw new IllegalArgumentException("Joystick index is out of range, should be 0-5");
}
if (axis >= HAL.kMaxJoystickAxes) {
if (axis < 0 || axis >= HAL.kMaxJoystickAxes) {
throw new IllegalArgumentException("Joystick axis is out of range");
}
@@ -451,7 +451,7 @@ public class DriverStation {
if (stick < 0 || stick >= kJoystickPorts) {
throw new IllegalArgumentException("Joystick index is out of range, should be 0-5");
}
if (pov >= HAL.kMaxJoystickPOVs) {
if (pov < 0 || pov >= HAL.kMaxJoystickPOVs) {
throw new IllegalArgumentException("Joystick POV is out of range");
}