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:
1 parent
29a4a4a5d1
commit
f88e0aaac0
1 file changed
+4
-4
@@ -1823,7 +1823,7 @@ void SDL_SetEventEnabled(Uint32 type, bool enabled)
|
|||||||
Uint8 lo = (type & 0xff);
|
Uint8 lo = (type & 0xff);
|
||||||
|
|
||||||
if (SDL_disabled_events[hi] &&
|
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;
|
current_state = false;
|
||||||
} else {
|
} else {
|
||||||
current_state = true;
|
current_state = true;
|
||||||
@@ -1832,7 +1832,7 @@ void SDL_SetEventEnabled(Uint32 type, bool enabled)
|
|||||||
if ((enabled != false) != current_state) {
|
if ((enabled != false) != current_state) {
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
SDL_assert(SDL_disabled_events[hi] != NULL);
|
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
|
// Gamepad events depend on joystick events
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@@ -1863,7 +1863,7 @@ void SDL_SetEventEnabled(Uint32 type, bool enabled)
|
|||||||
}
|
}
|
||||||
// Out of memory, nothing we can do...
|
// Out of memory, nothing we can do...
|
||||||
if (SDL_disabled_events[hi]) {
|
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);
|
SDL_FlushEvent(type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1882,7 +1882,7 @@ bool SDL_EventEnabled(Uint32 type)
|
|||||||
Uint8 lo = (type & 0xff);
|
Uint8 lo = (type & 0xff);
|
||||||
|
|
||||||
if (SDL_disabled_events[hi] &&
|
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;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in new issue
Block a user