diff options
author | SmallJoker <SmallJoker@users.noreply.github.com> | 2022-07-09 22:32:08 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-09 22:32:08 +0200 |
commit | 051181fa6ee00d8379e8a7dc7442b58342d4352b (patch) | |
tree | 58ad84f05310024b311c533684defdbeb5ee3e84 /src/client/joystick_controller.cpp | |
parent | 7c261118e06c630ea9ad00f20d7005b8edc108dd (diff) | |
download | minetest-051181fa6ee00d8379e8a7dc7442b58342d4352b.tar.gz minetest-051181fa6ee00d8379e8a7dc7442b58342d4352b.tar.bz2 minetest-051181fa6ee00d8379e8a7dc7442b58342d4352b.zip |
Enforce limits of settings that could cause buggy behaviour (#12450)
Enforces the setting value bounds that are currently only limited by the GUI (settingtypes.txt).
Diffstat (limited to 'src/client/joystick_controller.cpp')
-rw-r--r-- | src/client/joystick_controller.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/client/joystick_controller.cpp b/src/client/joystick_controller.cpp index aae73c62d..9e58b9f62 100644 --- a/src/client/joystick_controller.cpp +++ b/src/client/joystick_controller.cpp @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "gettime.h" #include "porting.h" #include "util/string.h" +#include "util/numeric.h" bool JoystickButtonCmb::isTriggered(const irr::SEvent::SJoystickEvent &ev) const { @@ -202,9 +203,9 @@ JoystickLayout create_dragonrise_gamecube_layout() } -JoystickController::JoystickController() : - doubling_dtime(g_settings->getFloat("repeat_joystick_button_time")) +JoystickController::JoystickController() { + doubling_dtime = std::max(g_settings->getFloat("repeat_joystick_button_time"), 0.001f); for (float &i : m_past_pressed_time) { i = 0; } @@ -217,19 +218,20 @@ void JoystickController::onJoystickConnect(const std::vector<irr::SJoystickInfo> s32 id = g_settings->getS32("joystick_id"); std::string layout = g_settings->get("joystick_type"); - if (id < 0 || (u16)id >= joystick_infos.size()) { + if (id < 0 || id >= (s32)joystick_infos.size()) { // TODO: auto detection id = 0; } - if (id >= 0 && (u16)id < joystick_infos.size()) { + if (id >= 0 && id < (s32)joystick_infos.size()) { if (layout.empty() || layout == "auto") setLayoutFromControllerName(joystick_infos[id].Name.c_str()); else setLayoutFromControllerName(layout); } - m_joystick_id = id; + // Irrlicht restriction. + m_joystick_id = rangelim(id, 0, UINT8_MAX); } void JoystickController::setLayoutFromControllerName(const std::string &name) |