[gnome-games] gamepad: Check bounds of mapping arrays
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] gamepad: Check bounds of mapping arrays
- Date: Mon, 25 Jul 2016 21:39:07 +0000 (UTC)
commit eb27d884f94acd8c62fc4142a8ce3f7f64a76218
Author: Adrien Plazas <kekun plazas laposte net>
Date: Mon Jul 25 23:34:21 2016 +0200
gamepad: Check bounds of mapping arrays
Return an invalid event if the axis or button number to access is out of
the bounds of the corresponding mappings array.
This avoid crashes in case of wrong gamepad mappings.
Fixes #313
src/gamepad/gamepad-mapping.vala | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)
---
diff --git a/src/gamepad/gamepad-mapping.vala b/src/gamepad/gamepad-mapping.vala
index 598c8c3..8e50942 100644
--- a/src/gamepad/gamepad-mapping.vala
+++ b/src/gamepad/gamepad-mapping.vala
@@ -84,7 +84,8 @@ private class Games.GamepadMapping : Object {
public GamepadMappedEvent get_axis_mapping (int axis_number) {
var event = GamepadMappedEvent ();
- event.type = axes_type[axis_number];
+ event.type = axis_number < axes_type.length ? axes_type[axis_number] :
+ GamepadInputType.INVALID;
switch (event.type) {
case GamepadInputType.AXIS:
event.axis = (StandardGamepadAxis) axes_value[axis_number];
@@ -101,7 +102,8 @@ private class Games.GamepadMapping : Object {
public GamepadMappedEvent get_button_mapping (int button_number) {
var event = GamepadMappedEvent ();
- event.type = buttons_type[button_number];
+ event.type = button_number < buttons_type.length ? buttons_type[button_number] :
+ GamepadInputType.INVALID;
switch (event.type) {
case GamepadInputType.AXIS:
event.axis = (StandardGamepadAxis) buttons_value[button_number];
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]