From b120b0872658335e1f23422e61b2e2b16f1aaab6 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Tue, 15 Oct 2019 15:35:07 -0500 Subject: [PATCH] ControllerEmu: Clamp results of trigger/slider states to prevent integer overflow later on. --- .../InputCommon/ControllerEmu/ControlGroup/MixedTriggers.cpp | 2 +- Source/Core/InputCommon/ControllerEmu/ControlGroup/Slider.cpp | 2 +- Source/Core/InputCommon/ControllerEmu/ControlGroup/Triggers.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/MixedTriggers.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/MixedTriggers.cpp index 3b3e68f291..4cd8df7874 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/MixedTriggers.cpp +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/MixedTriggers.cpp @@ -48,7 +48,7 @@ void MixedTriggers::GetState(u16* const digital, const u16* bitmasks, ControlSta { const ControlState button_value = ApplyDeadzone(controls[i]->control_ref->State(), deadzone); ControlState analog_value = - ApplyDeadzone(controls[trigger_count + i]->control_ref->State(), deadzone); + std::min(ApplyDeadzone(controls[trigger_count + i]->control_ref->State(), deadzone), 1.0); // Apply threshold: if (button_value > threshold) diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Slider.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Slider.cpp index f8865329b9..0b702b6657 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Slider.cpp +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Slider.cpp @@ -34,6 +34,6 @@ Slider::StateData Slider::GetState() const ControlState deadzone = m_deadzone_setting.GetValue() / 100; const ControlState state = controls[1]->control_ref->State() - controls[0]->control_ref->State(); - return {ApplyDeadzone(state, deadzone)}; + return {std::clamp(ApplyDeadzone(state, deadzone), -1.0, 1.0)}; } } // namespace ControllerEmu diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Triggers.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Triggers.cpp index 900f30de3c..abc74915e5 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Triggers.cpp +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Triggers.cpp @@ -28,7 +28,7 @@ Triggers::StateData Triggers::GetState() StateData result(trigger_count); for (size_t i = 0; i < trigger_count; ++i) - result.data[i] = ApplyDeadzone(controls[i]->control_ref->State(), deadzone); + result.data[i] = std::min(ApplyDeadzone(controls[i]->control_ref->State(), deadzone), 1.0); return result; }