events: Fix undefined behavior when disabling some event types

Shifting a signed int left by 31 is UB.

(cherry picked from commit 39d3148185)
This commit is contained in:
Cameron Gutman
2025-04-29 00:07:36 -05:00
parent 29a4a4a5d1
commit f88e0aaac0

View File

@@ -1823,7 +1823,7 @@ void SDL_SetEventEnabled(Uint32 type, bool enabled)
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 = false;
} else {
current_state = true;
@@ -1832,7 +1832,7 @@ void SDL_SetEventEnabled(Uint32 type, bool enabled)
if ((enabled != false) != current_state) {
if (enabled) {
SDL_assert(SDL_disabled_events[hi] != NULL);
SDL_disabled_events[hi]->bits[lo / 32] &= ~(1 << (lo & 31));
SDL_disabled_events[hi]->bits[lo / 32] &= ~(1U << (lo & 31));
// Gamepad events depend on joystick events
switch (type) {
@@ -1863,7 +1863,7 @@ void SDL_SetEventEnabled(Uint32 type, bool enabled)
}
// 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);
}
}
@@ -1882,7 +1882,7 @@ bool SDL_EventEnabled(Uint32 type)
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)))) {
return false;
} else {
return true;