events: Fix undefined behavior when disabling some event types

Shifting a signed int left by 31 is UB.

(cherry picked from commit 15fd3fcdc2)
This commit is contained in:
Cameron Gutman 2025-04-29 00:30:41 -05:00
parent f46ef5d76d
commit 24ccde693e
1 changed files with 3 additions and 3 deletions

View File

@ -1318,7 +1318,7 @@ Uint8 SDL_EventState(Uint32 type, int state)
Uint8 lo = (type & 0xff);
if (SDL_disabled_events[hi] &&
(SDL_disabled_events[hi]->bits[lo / 32] & (1 << (lo & 31)))) {
(SDL_disabled_events[hi]->bits[lo / 32] & (1U << (lo & 31)))) {
current_state = SDL_DISABLE;
} else {
current_state = SDL_ENABLE;
@ -1332,11 +1332,11 @@ Uint8 SDL_EventState(Uint32 type, int state)
}
/* Out of memory, nothing we can do... */
if (SDL_disabled_events[hi]) {
SDL_disabled_events[hi]->bits[lo / 32] |= (1 << (lo & 31));
SDL_disabled_events[hi]->bits[lo / 32] |= (1U << (lo & 31));
SDL_FlushEvent(type);
}
} else { // state == SDL_ENABLE
SDL_disabled_events[hi]->bits[lo / 32] &= ~(1 << (lo & 31));
SDL_disabled_events[hi]->bits[lo / 32] &= ~(1U << (lo & 31));
}
#ifndef SDL_JOYSTICK_DISABLED