linux/SDL_sysjoystick.c: Fix bug #3193: SDL-1.2
authorOzkan Sezer <sezeroz@gmail.com>
Tue, 07 Aug 2018 10:10:02 +0300
branchSDL-1.2
changeset 120763e05d58dc84f
parent 12066 20cbaf8965fb
child 12157 0f469a8b5110
linux/SDL_sysjoystick.c: Fix bug #3193:

Protect against any axis that isn't reported by EVIOCGBIT but still
sends EV_ABS events; patch from <maxxus@gmail.com>. Original issue
and description:

The Dualshock 3's motion sensors don't seem to be reported by the call
to EVIOCGBIT but they still send EV_ABS events. Because they're not
reported by EVIOCGBIT they're not assigned a proper axis ids and the
default of 0 is used, which is the valid id for the left analog sticks
left/right axis. The attached patch sets the default axis id to ABS_MAX
and then checks the axis id before performing the update. This will
protect against EV_ABS events for axes that aren't reported or handled
correctly.
src/joystick/linux/SDL_sysjoystick.c
     1.1 --- a/src/joystick/linux/SDL_sysjoystick.c	Thu Aug 02 10:47:28 2018 +0300
     1.2 +++ b/src/joystick/linux/SDL_sysjoystick.c	Tue Aug 07 10:10:02 2018 +0300
     1.3 @@ -826,6 +826,9 @@
     1.4  		return(-1);
     1.5  	}
     1.6  	SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata));
     1.7 +#if SDL_INPUT_LINUXEV
     1.8 +	SDL_memset(joystick->hwdata->abs_map, ABS_MAX, sizeof(*joystick->hwdata->abs_map)*ABS_MAX);
     1.9 +#endif
    1.10  	joystick->hwdata->fd = fd;
    1.11  
    1.12  	/* Set the joystick to non-blocking read mode */
    1.13 @@ -1123,15 +1126,17 @@
    1.14  							events[i].value);
    1.15  					break;
    1.16  				    default:
    1.17 -					events[i].value = EV_AxisCorrect(joystick, code, events[i].value);
    1.18 +					if (joystick->hwdata->abs_map[code] != ABS_MAX ) {
    1.19 +					  events[i].value = EV_AxisCorrect(joystick, code, events[i].value);
    1.20  #ifndef NO_LOGICAL_JOYSTICKS
    1.21 -					if (!LogicalJoystickAxis(joystick,
    1.22 +					  if (!LogicalJoystickAxis(joystick,
    1.23  				           joystick->hwdata->abs_map[code],
    1.24  					   events[i].value))
    1.25  #endif
    1.26 -					SDL_PrivateJoystickAxis(joystick,
    1.27 +					  SDL_PrivateJoystickAxis(joystick,
    1.28  				           joystick->hwdata->abs_map[code],
    1.29  					   events[i].value);
    1.30 +					}
    1.31  					break;
    1.32  				}
    1.33  				break;