From 051181fa6ee00d8379e8a7dc7442b58342d4352b Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Sat, 9 Jul 2022 22:32:08 +0200 Subject: 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). --- src/client/joystick_controller.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/client/joystick_controller.cpp') 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 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) -- cgit v1.2.3