1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-10-05 19:31:04 +00:00

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).
This commit is contained in:
SmallJoker 2022-07-09 22:32:08 +02:00 committed by GitHub
parent 7c261118e0
commit 051181fa6e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 74 additions and 56 deletions

View file

@ -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)