diff --git a/src/joystick/hidapi/SDL_hidapi_ps4.c b/src/joystick/hidapi/SDL_hidapi_ps4.c index 453996c3b..9d005b063 100644 --- a/src/joystick/hidapi/SDL_hidapi_ps4.c +++ b/src/joystick/hidapi/SDL_hidapi_ps4.c @@ -298,7 +298,7 @@ HIDAPI_DriverPS4_Rumble(SDL_Joystick *joystick, hid_device *dev, void *context, } if ((low_frequency_rumble || high_frequency_rumble) && duration_ms) { - ctx->rumble_expiration = SDL_GetTicks() + duration_ms; + ctx->rumble_expiration = SDL_GetTicks() + SDL_min(duration_ms, SDL_MAX_RUMBLE_DURATION_MS); } else { ctx->rumble_expiration = 0; } diff --git a/src/joystick/hidapi/SDL_hidapi_xbox360.c b/src/joystick/hidapi/SDL_hidapi_xbox360.c index 41e587747..e50f20874 100644 --- a/src/joystick/hidapi/SDL_hidapi_xbox360.c +++ b/src/joystick/hidapi/SDL_hidapi_xbox360.c @@ -381,7 +381,7 @@ HIDAPI_DriverXbox360_Rumble(SDL_Joystick *joystick, hid_device *dev, void *conte #endif /* __WIN32__ */ if ((low_frequency_rumble || high_frequency_rumble) && duration_ms) { - ctx->rumble_expiration = SDL_GetTicks() + duration_ms; + ctx->rumble_expiration = SDL_GetTicks() + SDL_min(duration_ms, SDL_MAX_RUMBLE_DURATION_MS); } else { ctx->rumble_expiration = 0; } diff --git a/src/joystick/hidapi/SDL_hidapi_xboxone.c b/src/joystick/hidapi/SDL_hidapi_xboxone.c index efd475dbf..54e07e810 100644 --- a/src/joystick/hidapi/SDL_hidapi_xboxone.c +++ b/src/joystick/hidapi/SDL_hidapi_xboxone.c @@ -298,7 +298,7 @@ HIDAPI_DriverXboxOne_Rumble(SDL_Joystick *joystick, hid_device *dev, void *conte } if ((low_frequency_rumble || high_frequency_rumble) && duration_ms) { - ctx->rumble_expiration = SDL_GetTicks() + duration_ms; + ctx->rumble_expiration = SDL_GetTicks() + SDL_min(duration_ms, SDL_MAX_RUMBLE_DURATION_MS); } else { ctx->rumble_expiration = 0; } diff --git a/src/joystick/hidapi/SDL_hidapijoystick_c.h b/src/joystick/hidapi/SDL_hidapijoystick_c.h index 0b141aacc..3acfc4736 100644 --- a/src/joystick/hidapi/SDL_hidapijoystick_c.h +++ b/src/joystick/hidapi/SDL_hidapijoystick_c.h @@ -43,6 +43,9 @@ #undef SDL_JOYSTICK_HIDAPI_XBOXONE #endif +/* Prevent rumble duration overflow */ +#define SDL_MAX_RUMBLE_DURATION_MS 0x0fffffff + typedef struct _SDL_HIDAPI_DeviceDriver { const char *hint;