Skip to content

Commit 15fd3fc

Browse files
committed
events: Fix undefined behavior when disabling some event types
Shifting a signed int left by 31 is UB.
1 parent 45b01d1 commit 15fd3fc

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/events/SDL_events.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,7 +1318,7 @@ Uint8 SDL_EventState(Uint32 type, int state)
13181318
Uint8 lo = (type & 0xff);
13191319

13201320
if (SDL_disabled_events[hi] &&
1321-
(SDL_disabled_events[hi]->bits[lo / 32] & (1 << (lo & 31)))) {
1321+
(SDL_disabled_events[hi]->bits[lo / 32] & (1U << (lo & 31)))) {
13221322
current_state = SDL_DISABLE;
13231323
} else {
13241324
current_state = SDL_ENABLE;
@@ -1332,11 +1332,11 @@ Uint8 SDL_EventState(Uint32 type, int state)
13321332
}
13331333
/* Out of memory, nothing we can do... */
13341334
if (SDL_disabled_events[hi]) {
1335-
SDL_disabled_events[hi]->bits[lo / 32] |= (1 << (lo & 31));
1335+
SDL_disabled_events[hi]->bits[lo / 32] |= (1U << (lo & 31));
13361336
SDL_FlushEvent(type);
13371337
}
13381338
} else { // state == SDL_ENABLE
1339-
SDL_disabled_events[hi]->bits[lo / 32] &= ~(1 << (lo & 31));
1339+
SDL_disabled_events[hi]->bits[lo / 32] &= ~(1U << (lo & 31));
13401340
}
13411341

13421342
#ifndef SDL_JOYSTICK_DISABLED

0 commit comments

Comments
 (0)