summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerEmu/ControlGroup
diff options
context:
space:
mode:
authorFiloppi <filippotarpini@hotmail.it>2021-05-05 00:01:20 +0300
committerFiloppi <filippotarpini@hotmail.it>2021-05-19 20:51:34 +0300
commita19a0096db4bbee3b7ae6411c0b6e801c091783e (patch)
tree7c9b3d6f3ca4d3f2bf84241e519387ec5700c05f /Source/Core/InputCommon/ControllerEmu/ControlGroup
parentd43a06ff6ad713f25b6b80ad6dc4bba8e003db04 (diff)
InputCommon: improve code that returns a controller attachment index
casting a value to a u32 when it's originally an int, and it's exposed as int to users, could end up in cases where a negative number would result as a positive one. This doesn't really affect the value range of the attachment enum, still I think the code was wrong. Heavily tested.
Diffstat (limited to 'Source/Core/InputCommon/ControllerEmu/ControlGroup')
-rw-r--r--Source/Core/InputCommon/ControllerEmu/ControlGroup/Attachments.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Attachments.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Attachments.cpp
index 6f980d8c60..18ccbc1966 100644
--- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Attachments.cpp
+++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Attachments.cpp
@@ -17,10 +17,11 @@ void Attachments::AddAttachment(std::unique_ptr<EmulatedController> att)
u32 Attachments::GetSelectedAttachment() const
{
- const u32 value = m_selection_value.GetValue();
+ // This is originally an int, treat it as such
+ const int value = m_selection_value.GetValue();
- if (value < m_attachments.size())
- return value;
+ if (value > 0 && static_cast<size_t>(value) < m_attachments.size())
+ return u32(value);
return 0;
}