Browse Source

events: Fix undefined behavior when disabling some event types

Shifting a signed int left by 31 is UB.

(cherry picked from commit 15fd3fcdc214d06dd5c12daf4a29772e994c6b7a)
Cameron Gutman 3 months ago
parent
commit
24ccde693e
1 changed files with 3 additions and 3 deletions
  1. 3 3
      src/events/SDL_events.c

+ 3 - 3
src/events/SDL_events.c

@@ -1318,7 +1318,7 @@ Uint8 SDL_EventState(Uint32 type, int state)
     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 = SDL_DISABLE;
         current_state = SDL_DISABLE;
     } else {
     } else {
         current_state = SDL_ENABLE;
         current_state = SDL_ENABLE;
@@ -1332,11 +1332,11 @@ Uint8 SDL_EventState(Uint32 type, int state)
             }
             }
             /* 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);
             }
             }
         } else { // state == SDL_ENABLE
         } 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
 #ifndef SDL_JOYSTICK_DISABLED