mirror of
https://github.com/SFML/SFML.git
synced 2024-11-25 04:41:05 +08:00
Assert against out of bounds array access in sf::Joystick
sf::JoystickManager is a private type but the sf::Joystick API calls into it so those asserts are still prone to fail due to incorrect user input. Yay for catching more UB :)
This commit is contained in:
parent
d6c18af926
commit
856a81f62b
@ -28,6 +28,8 @@
|
|||||||
#include <SFML/Window/Joystick.hpp>
|
#include <SFML/Window/Joystick.hpp>
|
||||||
#include <SFML/Window/JoystickManager.hpp>
|
#include <SFML/Window/JoystickManager.hpp>
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
@ -55,6 +57,7 @@ bool Joystick::hasAxis(unsigned int joystick, Axis axis)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool Joystick::isButtonPressed(unsigned int joystick, unsigned int button)
|
bool Joystick::isButtonPressed(unsigned int joystick, unsigned int button)
|
||||||
{
|
{
|
||||||
|
assert(button < Joystick::ButtonCount && "Button must be less than Joystick::ButtonCount");
|
||||||
return priv::JoystickManager::getInstance().getState(joystick).buttons[button];
|
return priv::JoystickManager::getInstance().getState(joystick).buttons[button];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,8 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Window/JoystickManager.hpp>
|
#include <SFML/Window/JoystickManager.hpp>
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
|
||||||
namespace sf::priv
|
namespace sf::priv
|
||||||
{
|
{
|
||||||
@ -41,6 +43,7 @@ JoystickManager& JoystickManager::getInstance()
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
const JoystickCaps& JoystickManager::getCapabilities(unsigned int joystick) const
|
const JoystickCaps& JoystickManager::getCapabilities(unsigned int joystick) const
|
||||||
{
|
{
|
||||||
|
assert(joystick < Joystick::Count && "Joystick index must be less than Joystick::Count");
|
||||||
return m_joysticks[joystick].capabilities;
|
return m_joysticks[joystick].capabilities;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,6 +51,7 @@ const JoystickCaps& JoystickManager::getCapabilities(unsigned int joystick) cons
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
const JoystickState& JoystickManager::getState(unsigned int joystick) const
|
const JoystickState& JoystickManager::getState(unsigned int joystick) const
|
||||||
{
|
{
|
||||||
|
assert(joystick < Joystick::Count && "Joystick index must be less than Joystick::Count");
|
||||||
return m_joysticks[joystick].state;
|
return m_joysticks[joystick].state;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,6 +59,7 @@ const JoystickState& JoystickManager::getState(unsigned int joystick) const
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
const Joystick::Identification& JoystickManager::getIdentification(unsigned int joystick) const
|
const Joystick::Identification& JoystickManager::getIdentification(unsigned int joystick) const
|
||||||
{
|
{
|
||||||
|
assert(joystick < Joystick::Count && "Joystick index must be less than Joystick::Count");
|
||||||
return m_joysticks[joystick].identification;
|
return m_joysticks[joystick].identification;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user