Commit 8a8f96df authored by Sam Lantinga's avatar Sam Lantinga

Fixed bug #853

 Ludwig Nussel      2009-10-18 05:34:18 PDT

src/joystick/linux/SDL_sysjoystick.c has some problems:

- test_bit() might break with strict aliasing
- test_bit() assumes array is Uint32 but its actually "unsigned long"
  on 64bit systems sizeof(long) != sizeof(Uint32).
- the keybit array is too small
- the arrays are unitialized so the number of
  detected buttons is quite random

--HG--
branch : SDL-1.2
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/branches/SDL-1.2%404109
parent ad338773
...@@ -374,13 +374,14 @@ static void LogicalSuffix(int logicalno, char* namebuf, int len) ...@@ -374,13 +374,14 @@ static void LogicalSuffix(int logicalno, char* namebuf, int len)
#if SDL_INPUT_LINUXEV #if SDL_INPUT_LINUXEV
#define test_bit(nr, addr) \ #define test_bit(nr, addr) \
(((1UL << ((nr) & 31)) & (((const Uint32 *) addr)[(nr) >> 5])) != 0) (((1UL << ((nr) % (sizeof(long) * 8))) & ((addr)[(nr) / (sizeof(long) * 8)])) != 0)
#define NBITS(x) ((((x)-1)/(sizeof(long) * 8))+1)
static int EV_IsJoystick(int fd) static int EV_IsJoystick(int fd)
{ {
unsigned long evbit[40]; unsigned long evbit[NBITS(EV_MAX)] = { 0 };
unsigned long keybit[40]; unsigned long keybit[NBITS(KEY_MAX)] = { 0 };
unsigned long absbit[40]; unsigned long absbit[NBITS(ABS_MAX)] = { 0 };
if ( (ioctl(fd, EVIOCGBIT(0, sizeof(evbit)), evbit) < 0) || if ( (ioctl(fd, EVIOCGBIT(0, sizeof(evbit)), evbit) < 0) ||
(ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) < 0) || (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) < 0) ||
...@@ -661,9 +662,9 @@ static SDL_bool JS_ConfigJoystick(SDL_Joystick *joystick, int fd) ...@@ -661,9 +662,9 @@ static SDL_bool JS_ConfigJoystick(SDL_Joystick *joystick, int fd)
static SDL_bool EV_ConfigJoystick(SDL_Joystick *joystick, int fd) static SDL_bool EV_ConfigJoystick(SDL_Joystick *joystick, int fd)
{ {
int i, t; int i, t;
unsigned long keybit[40]; unsigned long keybit[NBITS(KEY_MAX)] = { 0 };
unsigned long absbit[40]; unsigned long absbit[NBITS(ABS_MAX)] = { 0 };
unsigned long relbit[40]; unsigned long relbit[NBITS(REL_MAX)] = { 0 };
/* See if this device uses the new unified event API */ /* See if this device uses the new unified event API */
if ( (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) >= 0) && if ( (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) >= 0) &&
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment