Skip to content

Commit 33fd265

Browse files
committed
Bug 1604405 - Replace gamepad button array index with axis array index in Mac OS. r=baku
- Fixes wrong usage of button array index for axis id - Added more warning and conditions for avoiding crashes happen - Corrected aIndex vs aButton when checking button count. Differential Revision: https://phabricator.services.mozilla.com/D57423 --HG-- extra : moz-landing-system : lando
1 parent 4e6cac8 commit 33fd265

File tree

2 files changed

+44
-16
lines changed

2 files changed

+44
-16
lines changed

dom/gamepad/GamepadRemapping.cpp

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ class DefaultRemapper final : public GamepadRemapper {
110110

111111
virtual void RemapAxisMoveEvent(uint32_t aIndex, uint32_t aAxis,
112112
double aValue) const override {
113+
if (GetAxisCount() <= aAxis) {
114+
NS_WARNING(
115+
nsPrintfCString("Axis idx '%d' doesn't support in DefaultRemapper().",
116+
aAxis)
117+
.get());
118+
return;
119+
}
113120
RefPtr<GamepadPlatformService> service =
114121
GamepadPlatformService::GetParentService();
115122
if (!service) {
@@ -120,6 +127,13 @@ class DefaultRemapper final : public GamepadRemapper {
120127

121128
virtual void RemapButtonEvent(uint32_t aIndex, uint32_t aButton,
122129
bool aPressed) const override {
130+
if (GetButtonCount() <= aButton) {
131+
NS_WARNING(
132+
nsPrintfCString(
133+
"Button idx '%d' doesn't support in DefaultRemapper().", aButton)
134+
.get());
135+
return;
136+
}
123137
RefPtr<GamepadPlatformService> service =
124138
GamepadPlatformService::GetParentService();
125139
if (!service) {
@@ -190,7 +204,7 @@ class ADT1Remapper final : public GamepadRemapper {
190204
return;
191205
}
192206

193-
if (GetButtonCount() <= aIndex) {
207+
if (GetButtonCount() <= aButton) {
194208
NS_WARNING(
195209
nsPrintfCString("Button idx '%d' doesn't support in ADT1Remapper().",
196210
aButton)
@@ -263,7 +277,7 @@ class TwoAxesEightKeysRemapper final : public GamepadRemapper {
263277
return;
264278
}
265279

266-
if (GetButtonCount() <= aIndex) {
280+
if (GetButtonCount() <= aButton) {
267281
NS_WARNING(
268282
nsPrintfCString(
269283
"Button idx '%d' doesn't support in TwoAxesEightKeysRemapper().",
@@ -339,7 +353,7 @@ class StadiaControllerRemapper final : public GamepadRemapper {
339353
return;
340354
}
341355

342-
if (STADIA_BUTTON_COUNT <= aIndex) {
356+
if (STADIA_BUTTON_COUNT <= aButton) {
343357
NS_WARNING(
344358
nsPrintfCString(
345359
"Button idx '%d' doesn't support in StadiaControllerRemapper().",
@@ -531,7 +545,7 @@ class Dualshock4Remapper final : public GamepadRemapper {
531545
BUTTON_INDEX_META,
532546
DUALSHOCK_BUTTON_TOUCHPAD};
533547

534-
if (buttonMapping.size() <= aIndex) {
548+
if (buttonMapping.size() <= aButton) {
535549
NS_WARNING(nsPrintfCString(
536550
"Button idx '%d' doesn't support in Dualshock4Remapper().",
537551
aButton)
@@ -609,7 +623,7 @@ class LogitechDInputRemapper final : public GamepadRemapper {
609623
return;
610624
}
611625

612-
if (GetButtonCount() <= aIndex) {
626+
if (GetButtonCount() <= aButton) {
613627
NS_WARNING(
614628
nsPrintfCString(
615629
"Button idx '%d' doesn't support in LogitechDInputRemapper().",
@@ -642,6 +656,13 @@ class SwitchJoyConRemapper final : public GamepadRemapper {
642656

643657
virtual void RemapAxisMoveEvent(uint32_t aIndex, uint32_t aAxis,
644658
double aValue) const override {
659+
if (GetAxisCount() <= aAxis) {
660+
NS_WARNING(
661+
nsPrintfCString(
662+
"Axis idx '%d' doesn't support in SwitchJoyConRemapper().", aAxis)
663+
.get());
664+
return;
665+
}
645666
RefPtr<GamepadPlatformService> service =
646667
GamepadPlatformService::GetParentService();
647668
if (!service) {
@@ -675,6 +696,13 @@ class SwitchProRemapper final : public GamepadRemapper {
675696

676697
virtual void RemapAxisMoveEvent(uint32_t aIndex, uint32_t aAxis,
677698
double aValue) const override {
699+
if (GetAxisCount() <= aAxis) {
700+
NS_WARNING(
701+
nsPrintfCString(
702+
"Axis idx '%d' doesn't support in SwitchProRemapper().", aAxis)
703+
.get());
704+
return;
705+
}
678706
RefPtr<GamepadPlatformService> service =
679707
GamepadPlatformService::GetParentService();
680708
if (!service) {
@@ -759,7 +787,7 @@ class NvShieldRemapper final : public GamepadRemapper {
759787
return;
760788
}
761789

762-
if (GetButtonCount() <= aIndex) {
790+
if (GetButtonCount() <= aButton) {
763791
NS_WARNING(
764792
nsPrintfCString(
765793
"Button idx '%d' doesn't support in NvShieldRemapper().", aButton)
@@ -852,7 +880,7 @@ class NvShield2017Remapper final : public GamepadRemapper {
852880
return;
853881
}
854882

855-
if (GetButtonCount() <= aIndex) {
883+
if (GetButtonCount() <= aButton) {
856884
NS_WARNING(
857885
nsPrintfCString(
858886
"Button idx '%d' doesn't support in NvShield2017Remapper().",
@@ -936,7 +964,7 @@ class IBuffaloRemapper final : public GamepadRemapper {
936964
return;
937965
}
938966

939-
if (GetButtonCount() <= aIndex) {
967+
if (GetButtonCount() <= aButton) {
940968
NS_WARNING(
941969
nsPrintfCString(
942970
"Button idx '%d' doesn't support in IBuffaloRemapper().", aButton)
@@ -1107,7 +1135,7 @@ class BoomN64PsxRemapper final : public GamepadRemapper {
11071135
BUTTON_INDEX_DPAD_UP, BUTTON_INDEX_DPAD_RIGHT,
11081136
BUTTON_INDEX_DPAD_DOWN, BUTTON_INDEX_DPAD_LEFT};
11091137

1110-
if (buttonMapping.size() <= aIndex) {
1138+
if (buttonMapping.size() <= aButton) {
11111139
NS_WARNING(nsPrintfCString(
11121140
"Button idx '%d' doesn't support in BoomN64PsxRemapper().",
11131141
aButton)
@@ -1184,7 +1212,7 @@ class AnalogGamepadRemapper final : public GamepadRemapper {
11841212
return;
11851213
}
11861214

1187-
if (GetButtonCount() <= aIndex) {
1215+
if (GetButtonCount() <= aButton) {
11881216
NS_WARNING(
11891217
nsPrintfCString(
11901218
"Button idx '%d' doesn't support in AnalogGamepadRemapper().",
@@ -1280,7 +1308,7 @@ class RazerServalRemapper final : public GamepadRemapper {
12801308
return;
12811309
}
12821310

1283-
if (GetButtonCount() <= aIndex) {
1311+
if (GetButtonCount() <= aButton) {
12841312
NS_WARNING(
12851313
nsPrintfCString(
12861314
"Button idx '%d' doesn't support in RazerServalRemapper().",
@@ -1362,7 +1390,7 @@ class MogaProRemapper final : public GamepadRemapper {
13621390
return;
13631391
}
13641392

1365-
if (GetButtonCount() <= aIndex) {
1393+
if (GetButtonCount() <= aButton) {
13661394
NS_WARNING(
13671395
nsPrintfCString(
13681396
"Button idx '%d' doesn't support in MogaProRemapper().", aButton)
@@ -1443,7 +1471,7 @@ class OnLiveWirelessRemapper final : public GamepadRemapper {
14431471
return;
14441472
}
14451473

1446-
if (GetButtonCount() <= aIndex) {
1474+
if (GetButtonCount() <= aButton) {
14471475
NS_WARNING(
14481476
nsPrintfCString(
14491477
"Button idx '%d' doesn't support in OnLiveWirelessRemapper().",
@@ -1524,7 +1552,7 @@ class OUYARemapper final : public GamepadRemapper {
15241552
return;
15251553
}
15261554

1527-
if (GetButtonCount() <= aIndex) {
1555+
if (GetButtonCount() <= aButton) {
15281556
NS_WARNING(
15291557
nsPrintfCString("Button idx '%d' doesn't support in OUYARemapper().",
15301558
aButton)

dom/gamepad/cocoa/CocoaGamepad.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ void Gamepad::init(IOHIDDeviceRef aDevice, bool aDefaultRemapper) {
134134

135135
if (usagePage == kDesktopUsagePage && usage >= kAxisUsageMin &&
136136
usage <= kAxisUsageMax) {
137-
Axis axis = {aDefaultRemapper ? int(buttons.Length())
137+
Axis axis = {aDefaultRemapper ? int(axes.Length())
138138
: static_cast<int>(usage - kAxisUsageMin),
139139
element,
140140
usagePage,
@@ -147,7 +147,7 @@ void Gamepad::init(IOHIDDeviceRef aDevice, bool aDefaultRemapper) {
147147
IOHIDElementGetLogicalMax(element) -
148148
IOHIDElementGetLogicalMin(element) ==
149149
7) {
150-
Axis axis = {aDefaultRemapper ? int(buttons.Length())
150+
Axis axis = {aDefaultRemapper ? int(axes.Length())
151151
: static_cast<int>(usage - kAxisUsageMin),
152152
element,
153153
usagePage,

0 commit comments

Comments
 (0)