events: Fixed crash in SDL_SetEventEnabled.

This could happen if `enabled` was non-zero but not set to SDL_TRUE.

Static analysis tried to warn us!!

The added SDL_assert is meant to sanity check this, not pacify the analyzer;
this passes Clang's static analysis now, with or without the assert.

Fixes #9544.
main
Ryan C. Gordon 2024-04-15 12:40:29 -04:00
parent 8a45c38f48
commit 9f6f4dfcb9
No known key found for this signature in database
GPG Key ID: FA148B892AB48044
1 changed files with 3 additions and 7 deletions

View File

@ -1394,6 +1394,8 @@ void SDL_SetEventEnabled(Uint32 type, SDL_bool enabled)
Uint8 hi = ((type >> 8) & 0xff); Uint8 hi = ((type >> 8) & 0xff);
Uint8 lo = (type & 0xff); Uint8 lo = (type & 0xff);
enabled = !!enabled; // make sure this is definitely either SDL_TRUE or SDL_FALSE.
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] & (1 << (lo & 31)))) {
current_state = SDL_FALSE; current_state = SDL_FALSE;
@ -1403,14 +1405,8 @@ void SDL_SetEventEnabled(Uint32 type, SDL_bool enabled)
if (enabled != current_state) { if (enabled != current_state) {
if (enabled) { if (enabled) {
#ifdef _MSC_VER /* Visual Studio analyzer can't tell that SDL_disabled_events[hi] isn't NULL if enabled is true */ SDL_assert(SDL_disabled_events[hi] != NULL);
#pragma warning(push)
#pragma warning(disable : 6011)
#endif
SDL_disabled_events[hi]->bits[lo / 32] &= ~(1 << (lo & 31)); SDL_disabled_events[hi]->bits[lo / 32] &= ~(1 << (lo & 31));
#ifdef _MSC_VER
#pragma warning(pop)
#endif
/* Gamepad events depend on joystick events */ /* Gamepad events depend on joystick events */
switch (type) { switch (type) {