mirror of
https://github.com/Relintai/sdl2_frt.git
synced 2024-12-20 22:16:49 +01:00
Fixed bug 5155 - HIDAPI_JoystickDisconnected incorrect array shift
Anthony Pesch I was looking into my own input bug and noticed an issue in the HIDAPI code while looking over it. I don't have a controller that goes down this path to test and try to provoke the issue, but it looks pretty straight forward. The memmove to shift the joystick id array on disconnect isn't scaling the size by sizeof(SDL_JoystickID), likely corrupting the ids on disconnect.
This commit is contained in:
parent
a8400dc3bf
commit
d000c1cd6d
@ -631,7 +631,7 @@ HIDAPI_JoystickConnected(SDL_HIDAPI_Device *device, SDL_JoystickID *pJoystickID,
|
||||
void
|
||||
HIDAPI_JoystickDisconnected(SDL_HIDAPI_Device *device, SDL_JoystickID joystickID, SDL_bool is_external)
|
||||
{
|
||||
int i;
|
||||
int i, size;
|
||||
|
||||
for (i = 0; i < device->num_joysticks; ++i) {
|
||||
if (device->joysticks[i] == joystickID) {
|
||||
@ -640,8 +640,10 @@ HIDAPI_JoystickDisconnected(SDL_HIDAPI_Device *device, SDL_JoystickID joystickID
|
||||
HIDAPI_JoystickClose(joystick);
|
||||
}
|
||||
|
||||
SDL_memmove(&device->joysticks[i], &device->joysticks[i+1], device->num_joysticks - i - 1);
|
||||
size = (device->num_joysticks - i - 1) * sizeof(SDL_JoystickID);
|
||||
SDL_memmove(&device->joysticks[i], &device->joysticks[i+1], size);
|
||||
--device->num_joysticks;
|
||||
|
||||
if (!is_external) {
|
||||
--SDL_HIDAPI_numjoysticks;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user