diff --git a/src/joystick/hidapi/SDL_hidapijoystick.c b/src/joystick/hidapi/SDL_hidapijoystick.c index d5aea3e15..128ee9e53 100644 --- a/src/joystick/hidapi/SDL_hidapijoystick.c +++ b/src/joystick/hidapi/SDL_hidapijoystick.c @@ -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; }