Skip to content

Commit

Permalink
input_sdl.cpp: Ignore joystick buttons beyond maximum supported number.
Browse files Browse the repository at this point in the history
* Note that the code to map excess buttons to switches doesn't actually do anything useful while INPUT_MAX_BUTTONS and MAX_BUTTONS happen to be defined to the same number.
  • Loading branch information
cuavas committed Dec 7, 2019
1 parent 7c13daf commit a660815
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/osd/modules/input/input_sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,8 @@ class sdl_joystick_device : public sdl_device

case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:
joystick.buttons[sdlevent.jbutton.button] = (sdlevent.jbutton.state == SDL_PRESSED) ? 0x80 : 0;
if (sdlevent.jbutton.button < MAX_BUTTONS)
joystick.buttons[sdlevent.jbutton.button] = (sdlevent.jbutton.state == SDL_PRESSED) ? 0x80 : 0;
break;
}
}
Expand Down Expand Up @@ -1070,7 +1071,9 @@ class sdl_joystick_module : public sdl_input_module
}

// loop over all buttons
for (int button = 0; button < SDL_JoystickNumButtons(joy); button++)
if (SDL_JoystickNumButtons(joy) > MAX_BUTTONS)
osd_printf_verbose("Joystick: ... Has %d buttons which exceeds supported %d buttons\n", SDL_JoystickNumButtons(joy), MAX_BUTTONS);
for (int button = 0; (button < MAX_BUTTONS) && (button < SDL_JoystickNumButtons(joy)); button++)
{
input_item_id itemid;

Expand Down

0 comments on commit a660815

Please sign in to comment.