SDL: Additional cleanup exposed by building with a C++ compiler

From 00c409cff8f3e4f3c11313933f202166172161da Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sun, 25 Aug 2024 21:32:29 -0700
Subject: [PATCH] Additional cleanup exposed by building with a C++ compiler

---
 include/SDL3/SDL_audio.h                  |  1 +
 src/SDL_hints.c                           | 12 +++++-----
 src/audio/SDL_audio.c                     | 20 ++++++++---------
 src/audio/SDL_audioqueue.c                |  8 +++----
 src/audio/SDL_wave.c                      |  2 +-
 src/core/windows/SDL_windows.c            |  2 +-
 src/dialog/SDL_dialog_utils.c             |  4 ++--
 src/dialog/windows/SDL_windowsdialog.c    | 11 +++++----
 src/events/SDL_events.c                   |  8 +++----
 src/events/SDL_keyboard.c                 | 12 +++++-----
 src/filesystem/SDL_filesystem.c           |  2 +-
 src/joystick/SDL_gamepad.c                |  2 +-
 src/joystick/hidapi/SDL_hidapi_wii.c      |  4 ++--
 src/main/SDL_main_callbacks.c             |  6 ++---
 src/render/SDL_render.c                   |  4 ++--
 src/render/software/SDL_rotate.c          |  4 ++--
 src/render/vulkan/SDL_render_vulkan.c     |  2 +-
 src/time/windows/SDL_systime.c            |  2 +-
 src/video/SDL_blit_auto.c                 |  2 +-
 src/video/SDL_egl.c                       |  4 ++--
 src/video/SDL_video.c                     | 16 +++++++-------
 src/video/offscreen/SDL_offscreenvulkan.c |  4 ++--
 src/video/windows/SDL_windowsgameinput.c  |  4 ++--
 src/video/windows/SDL_windowswindow.c     | 18 +++++++--------
 test/testaudio.c                          | 27 +++++------------------
 test/testaudiostreamdynamicresample.c     | 23 +++----------------
 26 files changed, 84 insertions(+), 120 deletions(-)

diff --git a/include/SDL3/SDL_audio.h b/include/SDL3/SDL_audio.h
index a1b7e8cb66180..f74374105d76b 100644
--- a/include/SDL3/SDL_audio.h
+++ b/include/SDL3/SDL_audio.h
@@ -127,6 +127,7 @@ extern "C" {
  */
 typedef enum SDL_AudioFormat
 {
+    SDL_AUDIO_UNKNOWN   = 0x0000u,  /**< Unspecified audio format */
     SDL_AUDIO_U8        = 0x0008u,  /**< Unsigned 8-bit samples */
         /* SDL_DEFINE_AUDIO_FORMAT(0, 0, 0, 8), */
     SDL_AUDIO_S8        = 0x8008u,  /**< Signed 8-bit samples */
diff --git a/src/SDL_hints.c b/src/SDL_hints.c
index a3593051cd9b9..70fee997d16ab 100644
--- a/src/SDL_hints.c
+++ b/src/SDL_hints.c
@@ -86,7 +86,7 @@ SDL_bool SDL_SetHintWithPriority(const char *name, const char *value, SDL_HintPr
 
     SDL_LockProperties(hints);
 
-    SDL_Hint *hint = SDL_GetPointerProperty(hints, name, NULL);
+    SDL_Hint *hint = (SDL_Hint *)SDL_GetPointerProperty(hints, name, NULL);
     if (hint) {
         if (priority >= hint->priority) {
             if (hint->value != value && (!value || !hint->value || SDL_strcmp(hint->value, value) != 0)) {
@@ -137,7 +137,7 @@ SDL_bool SDL_ResetHint(const char *name)
 
     SDL_LockProperties(hints);
 
-    SDL_Hint *hint = SDL_GetPointerProperty(hints, name, NULL);
+    SDL_Hint *hint = (SDL_Hint *)SDL_GetPointerProperty(hints, name, NULL);
     if (hint) {
         if ((!env && hint->value) || (env && !hint->value) || (env && SDL_strcmp(env, hint->value) != 0)) {
             for (SDL_HintWatch *entry = hint->callbacks; entry;) {
@@ -160,7 +160,7 @@ SDL_bool SDL_ResetHint(const char *name)
 
 static void SDLCALL ResetHintsCallback(void *userdata, SDL_PropertiesID hints, const char *name)
 {
-    SDL_Hint *hint = SDL_GetPointerProperty(hints, name, NULL);
+    SDL_Hint *hint = (SDL_Hint *)SDL_GetPointerProperty(hints, name, NULL);
     if (!hint) {
         return;  // uh...okay.
     }
@@ -202,7 +202,7 @@ const char *SDL_GetHint(const char *name)
     if (hints) {
         SDL_LockProperties(hints);
 
-        SDL_Hint *hint = SDL_GetPointerProperty(hints, name, NULL);
+        SDL_Hint *hint = (SDL_Hint *)SDL_GetPointerProperty(hints, name, NULL);
         if (hint) {
             if (!result || hint->priority == SDL_HINT_OVERRIDE) {
                 result = SDL_GetPersistentString(hint->value);
@@ -275,7 +275,7 @@ SDL_bool SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *
 
     SDL_DelHintCallback(name, callback, userdata);
 
-    SDL_Hint *hint = SDL_GetPointerProperty(hints, name, NULL);
+    SDL_Hint *hint = (SDL_Hint *)SDL_GetPointerProperty(hints, name, NULL);
     if (hint) {
         result = true;
     } else {  // Need to add a hint entry for this watcher
@@ -317,7 +317,7 @@ void SDL_DelHintCallback(const char *name, SDL_HintCallback callback, void *user
     }
 
     SDL_LockProperties(hints);
-    SDL_Hint *hint = SDL_GetPointerProperty(hints, name, NULL);
+    SDL_Hint *hint = (SDL_Hint *)SDL_GetPointerProperty(hints, name, NULL);
     if (hint) {
         SDL_HintWatch *prev = NULL;
         for (SDL_HintWatch *entry = hint->callbacks; entry; entry = entry->next) {
diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c
index 948ea242dda84..e50170583a499 100644
--- a/src/audio/SDL_audio.c
+++ b/src/audio/SDL_audio.c
@@ -1570,7 +1570,7 @@ static SDL_AudioFormat ParseAudioFormatString(const char *string)
         CHECK_FMT_STRING(F32);
         #undef CHECK_FMT_STRING
     }
-    return 0;
+    return SDL_AUDIO_UNKNOWN;
 }
 
 static void PrepareAudioFormat(bool recording, SDL_AudioSpec *spec)
@@ -1601,7 +1601,7 @@ static void PrepareAudioFormat(bool recording, SDL_AudioSpec *spec)
 
     if (spec->format == 0) {
         const SDL_AudioFormat val = ParseAudioFormatString(SDL_GetHint(SDL_HINT_AUDIO_FORMAT));
-        spec->format = (val != 0) ? val : (recording ? DEFAULT_AUDIO_RECORDING_FORMAT : DEFAULT_AUDIO_PLAYBACK_FORMAT);
+        spec->format = (val != SDL_AUDIO_UNKNOWN) ? val : (recording ? DEFAULT_AUDIO_RECORDING_FORMAT : DEFAULT_AUDIO_PLAYBACK_FORMAT);
     }
 }
 
@@ -2151,14 +2151,14 @@ SDL_bool SDL_ResumeAudioStreamDevice(SDL_AudioStream *stream)
 #define NUM_FORMATS 8
 // always favor Float32 in native byte order, since we're probably going to convert to that for processing anyhow.
 static const SDL_AudioFormat format_list[NUM_FORMATS][NUM_FORMATS + 1] = {
-    { SDL_AUDIO_U8, NATIVE(F32),  SWAPPED(F32), SDL_AUDIO_S8, NATIVE(S16),  SWAPPED(S16), NATIVE(S32),  SWAPPED(S32), 0 },
-    { SDL_AUDIO_S8, NATIVE(F32),  SWAPPED(F32), SDL_AUDIO_U8, NATIVE(S16),  SWAPPED(S16), NATIVE(S32),  SWAPPED(S32), 0 },
-    { NATIVE(S16),  NATIVE(F32),  SWAPPED(F32), SWAPPED(S16), NATIVE(S32),  SWAPPED(S32), SDL_AUDIO_U8, SDL_AUDIO_S8, 0 },
-    { SWAPPED(S16), NATIVE(F32),  SWAPPED(F32), NATIVE(S16),  SWAPPED(S32), NATIVE(S32),  SDL_AUDIO_U8, SDL_AUDIO_S8, 0 },
-    { NATIVE(S32),  NATIVE(F32),  SWAPPED(F32), SWAPPED(S32), NATIVE(S16),  SWAPPED(S16), SDL_AUDIO_U8, SDL_AUDIO_S8, 0 },
-    { SWAPPED(S32), NATIVE(F32),  SWAPPED(F32), NATIVE(S32),  SWAPPED(S16), NATIVE(S16),  SDL_AUDIO_U8, SDL_AUDIO_S8, 0 },
-    { NATIVE(F32),  SWAPPED(F32), NATIVE(S32),  SWAPPED(S32), NATIVE(S16),  SWAPPED(S16), SDL_AUDIO_U8, SDL_AUDIO_S8, 0 },
-    { SWAPPED(F32), NATIVE(F32),  SWAPPED(S32), NATIVE(S32),  SWAPPED(S16), NATIVE(S16),  SDL_AUDIO_U8, SDL_AUDIO_S8, 0 },
+    { SDL_AUDIO_U8, NATIVE(F32),  SWAPPED(F32), SDL_AUDIO_S8, NATIVE(S16),  SWAPPED(S16), NATIVE(S32),  SWAPPED(S32), SDL_AUDIO_UNKNOWN },
+    { SDL_AUDIO_S8, NATIVE(F32),  SWAPPED(F32), SDL_AUDIO_U8, NATIVE(S16),  SWAPPED(S16), NATIVE(S32),  SWAPPED(S32), SDL_AUDIO_UNKNOWN },
+    { NATIVE(S16),  NATIVE(F32),  SWAPPED(F32), SWAPPED(S16), NATIVE(S32),  SWAPPED(S32), SDL_AUDIO_U8, SDL_AUDIO_S8, SDL_AUDIO_UNKNOWN },
+    { SWAPPED(S16), NATIVE(F32),  SWAPPED(F32), NATIVE(S16),  SWAPPED(S32), NATIVE(S32),  SDL_AUDIO_U8, SDL_AUDIO_S8, SDL_AUDIO_UNKNOWN },
+    { NATIVE(S32),  NATIVE(F32),  SWAPPED(F32), SWAPPED(S32), NATIVE(S16),  SWAPPED(S16), SDL_AUDIO_U8, SDL_AUDIO_S8, SDL_AUDIO_UNKNOWN },
+    { SWAPPED(S32), NATIVE(F32),  SWAPPED(F32), NATIVE(S32),  SWAPPED(S16), NATIVE(S16),  SDL_AUDIO_U8, SDL_AUDIO_S8, SDL_AUDIO_UNKNOWN },
+    { NATIVE(F32),  SWAPPED(F32), NATIVE(S32),  SWAPPED(S32), NATIVE(S16),  SWAPPED(S16), SDL_AUDIO_U8, SDL_AUDIO_S8, SDL_AUDIO_UNKNOWN },
+    { SWAPPED(F32), NATIVE(F32),  SWAPPED(S32), NATIVE(S32),  SWAPPED(S16), NATIVE(S16),  SDL_AUDIO_U8, SDL_AUDIO_S8, SDL_AUDIO_UNKNOWN },
 };
 
 #undef NATIVE
diff --git a/src/audio/SDL_audioqueue.c b/src/audio/SDL_audioqueue.c
index 039a65b57f437..ec5800be4064b 100644
--- a/src/audio/SDL_audioqueue.c
+++ b/src/audio/SDL_audioqueue.c
@@ -233,7 +233,7 @@ SDL_AudioTrack *SDL_CreateAudioTrack(
     Uint8 *data, size_t len, size_t capacity,
     SDL_ReleaseAudioBufferCallback callback, void *userdata)
 {
-    SDL_AudioTrack *track = AllocMemoryPoolBlock(&queue->track_pool);
+    SDL_AudioTrack *track = (SDL_AudioTrack *)AllocMemoryPoolBlock(&queue->track_pool);
 
     if (!track) {
         return NULL;
@@ -261,14 +261,14 @@ SDL_AudioTrack *SDL_CreateAudioTrack(
 
 static void SDLCALL FreeChunkedAudioBuffer(void *userdata, const void *buf, int len)
 {
-    SDL_AudioQueue *queue = userdata;
+    SDL_AudioQueue *queue = (SDL_AudioQueue *)userdata;
 
     FreeMemoryPoolBlock(&queue->chunk_pool, (void *)buf);
 }
 
 static SDL_AudioTrack *CreateChunkedAudioTrack(SDL_AudioQueue *queue, const SDL_AudioSpec *spec, const int *chmap)
 {
-    void *chunk = AllocMemoryPoolBlock(&queue->chunk_pool);
+    Uint8 *chunk = (Uint8 *)AllocMemoryPoolBlock(&queue->chunk_pool);
 
     if (!chunk) {
         return NULL;
@@ -636,7 +636,7 @@ bool SDL_ResetAudioQueueHistory(SDL_AudioQueue *queue, int num_frames)
     Uint8 *history_buffer = queue->history_buffer;
 
     if (queue->history_capacity < length) {
-        history_buffer = SDL_aligned_alloc(SDL_GetSIMDAlignment(), length);
+        history_buffer = (Uint8 *)SDL_aligned_alloc(SDL_GetSIMDAlignment(), length);
         if (!history_buffer) {
             return false;
         }
diff --git a/src/audio/SDL_wave.c b/src/audio/SDL_wave.c
index 88e71fd1db5b1..11012c5f47af4 100644
--- a/src/audio/SDL_wave.c
+++ b/src/audio/SDL_wave.c
@@ -2032,7 +2032,7 @@ static bool WaveLoad(SDL_IOStream *src, WaveFile *file, SDL_AudioSpec *spec, Uin
      */
     spec->freq = format->frequency;
     spec->channels = (Uint8)format->channels;
-    spec->format = 0;
+    spec->format = SDL_AUDIO_UNKNOWN;
 
     switch (format->encoding) {
     case MS_ADPCM_CODE:
diff --git a/src/core/windows/SDL_windows.c b/src/core/windows/SDL_windows.c
index 397c37e77e4f6..393cefea8a0cb 100644
--- a/src/core/windows/SDL_windows.c
+++ b/src/core/windows/SDL_windows.c
@@ -377,7 +377,7 @@ SDL_AudioFormat SDL_WaveFormatExToSDLFormat(WAVEFORMATEX *waveformat)
             return SDL_AUDIO_S32;
         }
     }
-    return 0;
+    return SDL_AUDIO_UNKNOWN;
 }
 
 
diff --git a/src/dialog/SDL_dialog_utils.c b/src/dialog/SDL_dialog_utils.c
index bbca9d0e692c2..e031721ce0eab 100644
--- a/src/dialog/SDL_dialog_utils.c
+++ b/src/dialog/SDL_dialog_utils.c
@@ -63,7 +63,7 @@ char *convert_filters(const SDL_DialogFileFilter *filters, int nfilters,
         new_length = SDL_strlen(combined) + SDL_strlen(converted)
                    + SDL_strlen(terminator) + 1;
 
-        new_combined = SDL_realloc(combined, new_length);
+        new_combined = (char *)SDL_realloc(combined, new_length);
 
         if (!new_combined) {
             SDL_free(converted);
@@ -82,7 +82,7 @@ char *convert_filters(const SDL_DialogFileFilter *filters, int nfilters,
     if (!filters->name || !filters->pattern) {
         new_length = SDL_strlen(combined) + SDL_strlen(suffix) + 1;
 
-        new_combined = SDL_realloc(combined, new_length);
+        new_combined = (char *)SDL_realloc(combined, new_length);
 
         if (!new_combined) {
             SDL_free(combined);
diff --git a/src/dialog/windows/SDL_windowsdialog.c b/src/dialog/windows/SDL_windowsdialog.c
index 405b2a9c1717b..6fb8650385b8e 100644
--- a/src/dialog/windows/SDL_windowsdialog.c
+++ b/src/dialog/windows/SDL_windowsdialog.c
@@ -172,8 +172,7 @@ void windows_ShowFileDialog(void *ptr)
         }
 
         int filter_wlen = MultiByteToWideChar(CP_UTF8, 0, filterlist, filter_len, NULL, 0);
-        filter_wchar = SDL_malloc(filter_wlen * sizeof(wchar_t));
-
+        filter_wchar = (wchar_t *)SDL_malloc(filter_wlen * sizeof(wchar_t));
         if (!filter_wchar) {
             SDL_free(filterlist);
             callback(userdata, NULL, -1);
@@ -439,7 +438,7 @@ void SDL_ShowOpenFileDialog(SDL_DialogFileCallback callback, void* userdata, SDL
         return;
     }
 
-    args = SDL_malloc(sizeof(winArgs));
+    args = (winArgs *)SDL_malloc(sizeof(*args));
     if (args == NULL) {
         callback(userdata, NULL, -1);
         return;
@@ -450,7 +449,7 @@ void SDL_ShowOpenFileDialog(SDL_DialogFileCallback callback, void* userdata, SDL
     args->nfilters = nfilters;
     args->default_file = default_location;
     args->parent = window;
-    args->flags = (allow_many == true) ? OFN_ALLOWMULTISELECT : 0;
+    args->flags = (allow_many != SDL_FALSE) ? OFN_ALLOWMULTISELECT : 0;
     args->callback = callback;
     args->userdata = userdata;
 
@@ -476,7 +475,7 @@ void SDL_ShowSaveFileDialog(SDL_DialogFileCallback callback, void* userdata, SDL
         return;
     }
 
-    args = SDL_malloc(sizeof(winArgs));
+    args = (winArgs *)SDL_malloc(sizeof(*args));
     if (args == NULL) {
         callback(userdata, NULL, -1);
         return;
@@ -513,7 +512,7 @@ void SDL_ShowOpenFolderDialog(SDL_DialogFileCallback callback, void* userdata, S
         return;
     }
 
-    args = SDL_malloc(sizeof(winFArgs));
+    args = (winFArgs *)SDL_malloc(sizeof(*args));
     if (args == NULL) {
         callback(userdata, NULL, -1);
         return;
diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c
index f8b57e2059875..564c483dfa90d 100644
--- a/src/events/SDL_events.c
+++ b/src/events/SDL_events.c
@@ -123,7 +123,7 @@ static SDL_TemporaryMemoryState *SDL_GetTemporaryMemoryState(bool create)
 {
     SDL_TemporaryMemoryState *state;
 
-    state = SDL_GetTLS(&SDL_temporary_memory);
+    state = (SDL_TemporaryMemoryState *)SDL_GetTLS(&SDL_temporary_memory);
     if (!state) {
         if (!create) {
             return NULL;
@@ -298,7 +298,7 @@ void *SDL_AllocateTemporaryMemory(size_t size)
 const char *SDL_CreateTemporaryString(const char *string)
 {
     if (string) {
-        return SDL_FreeLater(SDL_strdup(string));
+        return (const char *)SDL_FreeLater(SDL_strdup(string));
     }
     return NULL;
 }
@@ -1634,8 +1634,6 @@ void SDL_SetEventEnabled(Uint32 type, SDL_bool enabled)
     Uint8 hi = ((type >> 8) & 0xff);
     Uint8 lo = (type & 0xff);
 
-    enabled = !!enabled;  // make sure this is definitely either true or false.
-
     if (SDL_disabled_events[hi] &&
         (SDL_disabled_events[hi]->bits[lo / 32] & (1 << (lo & 31)))) {
         current_state = false;
@@ -1643,7 +1641,7 @@ void SDL_SetEventEnabled(Uint32 type, SDL_bool enabled)
         current_state = true;
     }
 
-    if (enabled != current_state) {
+    if ((enabled != SDL_FALSE) != current_state) {
         if (enabled) {
             SDL_assert(SDL_disabled_events[hi] != NULL);
             SDL_disabled_events[hi]->bits[lo / 32] &= ~(1 << (lo & 31));
diff --git a/src/events/SDL_keyboard.c b/src/events/SDL_keyboard.c
index f60732275f84b..0cff195c71e2b 100644
--- a/src/events/SDL_keyboard.c
+++ b/src/events/SDL_keyboard.c
@@ -214,14 +214,14 @@ const char *SDL_GetKeyboardNameForID(SDL_KeyboardID instance_id)
 void SDL_ResetKeyboard(void)
 {
     SDL_Keyboard *keyboard = &SDL_keyboard;
-    SDL_Scancode scancode;
+    int scancode;
 
 #ifdef DEBUG_KEYBOARD
     printf("Resetting keyboard\n");
 #endif
-    for (scancode = (SDL_Scancode)0; scancode < SDL_NUM_SCANCODES; ++scancode) {
+    for (scancode = SDL_SCANCODE_UNKNOWN; scancode < SDL_NUM_SCANCODES; ++scancode) {
         if (keyboard->keystate[scancode] == SDL_PRESSED) {
-            SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, 0, scancode, SDL_RELEASED);
+            SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, 0, (SDL_Scancode)scancode, SDL_RELEASED);
         }
     }
 }
@@ -696,12 +696,12 @@ bool SDL_SendKeyboardKeyAutoRelease(Uint64 timestamp, SDL_Scancode scancode)
 void SDL_ReleaseAutoReleaseKeys(void)
 {
     SDL_Keyboard *keyboard = &SDL_keyboard;
-    SDL_Scancode scancode;
+    int scancode;
 
     if (keyboard->autorelease_pending) {
         for (scancode = SDL_SCANCODE_UNKNOWN; scancode < SDL_NUM_SCANCODES; ++scancode) {
             if (keyboard->keysource[scancode] == KEYBOARD_AUTORELEASE) {
-                SDL_SendKeyboardKeyInternal(0, KEYBOARD_AUTORELEASE, SDL_GLOBAL_KEYBOARD_ID, 0, scancode, SDL_RELEASED);
+                SDL_SendKeyboardKeyInternal(0, KEYBOARD_AUTORELEASE, SDL_GLOBAL_KEYBOARD_ID, 0, (SDL_Scancode)scancode, SDL_RELEASED);
             }
         }
         keyboard->autorelease_pending = false;
@@ -718,7 +718,7 @@ void SDL_ReleaseAutoReleaseKeys(void)
 bool SDL_HardwareKeyboardKeyPressed(void)
 {
     SDL_Keyboard *keyboard = &SDL_keyboard;
-    SDL_Scancode scancode;
+    int scancode;
 
     for (scancode = SDL_SCANCODE_UNKNOWN; scancode < SDL_NUM_SCANCODES; ++scancode) {
         if (keyboard->keysource[scancode] & KEYBOARD_HARDWARE) {
diff --git a/src/filesystem/SDL_filesystem.c b/src/filesystem/SDL_filesystem.c
index 25e2d316e4466..5b16a4e1f8734 100644
--- a/src/filesystem/SDL_filesystem.c
+++ b/src/filesystem/SDL_filesystem.c
@@ -221,7 +221,7 @@ static char *CaseFoldUtf8String(const char *fname)
 
     if (remaining > 0) {
         SDL_assert(allocation > remaining);
-        ptr = SDL_realloc(result, allocation - remaining);  // shrink it down.
+        ptr = (char *)SDL_realloc(result, allocation - remaining);  // shrink it down.
         if (ptr) {  // shouldn't fail, but if it does, `result` is still valid.
             result = ptr;
         }
diff --git a/src/joystick/SDL_gamepad.c b/src/joystick/SDL_gamepad.c
index d160cad06a665..d374fc21e41ff 100644
--- a/src/joystick/SDL_gamepad.c
+++ b/src/joystick/SDL_gamepad.c
@@ -3132,7 +3132,7 @@ SDL_bool SDL_SetGamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type,
                 SDL_JoystickSensorInfo *sensor = &joystick->sensors[i];
 
                 if (sensor->type == type) {
-                    if (sensor->enabled == enabled) {
+                    if (sensor->enabled == (enabled != SDL_FALSE)) {
                         SDL_UnlockJoysticks();
                         return true;
                     }
diff --git a/src/joystick/hidapi/SDL_hidapi_wii.c b/src/joystick/hidapi/SDL_hidapi_wii.c
index 8768bfa715afa..c92ef6afa1196 100644
--- a/src/joystick/hidapi/SDL_hidapi_wii.c
+++ b/src/joystick/hidapi/SDL_hidapi_wii.c
@@ -257,7 +257,7 @@ static bool WriteRegister(SDL_DriverWii_Context *ctx, Uint32 address, const Uint
 
     SDL_zeroa(writeRequest);
     writeRequest[0] = k_eWiiOutputReportIDs_WriteMemory;
-    writeRequest[1] = (Uint8)(0x04 | ctx->m_bRumbleActive);
+    writeRequest[1] = (Uint8)(0x04 | (Uint8)ctx->m_bRumbleActive);
     writeRequest[2] = (address >> 16) & 0xff;
     writeRequest[3] = (address >> 8) & 0xff;
     writeRequest[4] = address & 0xff;
@@ -286,7 +286,7 @@ static bool ReadRegister(SDL_DriverWii_Context *ctx, Uint32 address, int size, b
     Uint8 readRequest[7];
 
     readRequest[0] = k_eWiiOutputReportIDs_ReadMemory;
-    readRequest[1] = (Uint8)(0x04 | ctx->m_bRumbleActive);
+    readRequest[1] = (Uint8)(0x04 | (Uint8)ctx->m_bRumbleActive);
     readRequest[2] = (address >> 16) & 0xff;
     readRequest[3] = (address >> 8) & 0xff;
     readRequest[4] = address & 0xff;
diff --git a/src/main/SDL_main_callbacks.c b/src/main/SDL_main_callbacks.c
index 236662015d733..284aaf90034ec 100644
--- a/src/main/SDL_main_callbacks.c
+++ b/src/main/SDL_main_callbacks.c
@@ -110,7 +110,7 @@ SDL_AppResult SDL_InitMainCallbacks(int argc, char* argv[], SDL_AppInit_func app
         }
     }
 
-    return SDL_AtomicGet(&apprc);
+    return (SDL_AppResult)SDL_AtomicGet(&apprc);
 }
 
 SDL_AppResult SDL_IterateMainCallbacks(bool pump_events)
@@ -120,11 +120,11 @@ SDL_AppResult SDL_IterateMainCallbacks(bool pump_events)
     }
     SDL_DispatchMainCallbackEvents();
 
-    SDL_AppResult rc = SDL_AtomicGet(&apprc);
+    SDL_AppResult rc = (SDL_AppResult)SDL_AtomicGet(&apprc);
     if (rc == SDL_APP_CONTINUE) {
         rc = SDL_main_iteration_callback(SDL_main_appstate);
         if (!SDL_AtomicCompareAndSwap(&apprc, SDL_APP_CONTINUE, rc)) {
-            rc = SDL_AtomicGet(&apprc); // something else already set a quit result, keep that.
+            rc = (SDL_AppResult)SDL_AtomicGet(&apprc); // something else already set a quit result, keep that.
         }
     }
     return rc;
diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c
index a5babc7e0e4fb..e12924c1c6d55 100644
--- a/src/render/SDL_render.c
+++ b/src/render/SDL_render.c
@@ -1286,7 +1286,7 @@ static bool IsSupportedFormat(SDL_Renderer *renderer, SDL_PixelFormat format)
     return false;
 }
 
-static Uint32 GetClosestSupportedFormat(SDL_Renderer *renderer, SDL_PixelFormat format)
+static SDL_PixelFormat GetClosestSupportedFormat(SDL_Renderer *renderer, SDL_PixelFormat format)
 {
     int i;
 
@@ -1405,7 +1405,7 @@ SDL_Texture *SDL_CreateTextureWithProperties(SDL_Renderer *renderer, SDL_Propert
             return NULL;
         }
     } else {
-        int closest_format;
+        SDL_PixelFormat closest_format;
         SDL_PropertiesID native_props = SDL_CreateProperties();
 
         if (!texture_is_fourcc_and_target) {
diff --git a/src/render/software/SDL_rotate.c b/src/render/software/SDL_rotate.c
index e7278b285a9ad..9799d3efc945b 100644
--- a/src/render/software/SDL_rotate.c
+++ b/src/render/software/SDL_rotate.c
@@ -492,7 +492,7 @@ SDL_Surface *SDLgfx_rotateSurface(SDL_Surface *src, double angle, int smooth, in
     int is8bit, angle90;
     SDL_BlendMode blendmode;
     Uint32 colorkey = 0;
-    int colorKeyAvailable = false;
+    bool colorKeyAvailable = false;
     double sangleinv, cangleinv;
 
     // Sanity check
@@ -538,7 +538,7 @@ SDL_Surface *SDLgfx_rotateSurface(SDL_Surface *src, double angle, int smooth, in
 
     SDL_GetSurfaceBlendMode(src, &blendmode);
 
-    if (colorKeyAvailable == true) {
+    if (colorKeyAvailable) {
         // If available, the colorkey will be used to discard the pixels that are outside of the rotated area.
         SDL_SetSurfaceColorKey(rz_dst, true, colorkey);
         SDL_FillSurfaceRect(rz_dst, NULL, colorkey);
diff --git a/src/render/vulkan/SDL_render_vulkan.c b/src/render/vulkan/SDL_render_vulkan.c
index 335d12c1ae84a..fbc558e447326 100644
--- a/src/render/vulkan/SDL_render_vulkan.c
+++ b/src/render/vulkan/SDL_render_vulkan.c
@@ -2165,7 +2165,7 @@ static VkResult VULKAN_CreateSwapChain(SDL_Renderer *renderer, int w, int h)
     swapchainCreateInfo.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
     swapchainCreateInfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
     swapchainCreateInfo.preTransform = rendererData->surfaceCapabilities.currentTransform;
-    swapchainCreateInfo.compositeAlpha = (renderer->window->flags & SDL_WINDOW_TRANSPARENT) ? 0 : VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
+    swapchainCreateInfo.compositeAlpha = (renderer->window->flags & SDL_WINDOW_TRANSPARENT) ? (VkCompositeAlphaFlagBitsKHR)0 : VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
     swapchainCreateInfo.presentMode = presentMode;
     swapchainCreateInfo.clipped = VK_TRUE;
     swapchainCreateInfo.oldSwapchain = rendererData->swapchain;
diff --git a/src/time/windows/SDL_systime.c b/src/time/windows/SDL_systime.c
index 3070935e8b70b..5dc6480fc4672 100644
--- a/src/time/windows/SDL_systime.c
+++ b/src/time/windows/SDL_systime.c
@@ -93,7 +93,7 @@ SDL_bool SDL_GetCurrentTime(SDL_Time *ticks)
 
     // Only available in Win8/Server 2012 or higher.
     if (!pGetSystemTimePreciseAsFileTime && !load_attempted) {
-        HANDLE kernel32 = GetModuleHandle(TEXT("kernel32.dll"));
+        HMODULE kernel32 = GetModuleHandle(TEXT("kernel32.dll"));
         if (kernel32) {
             pGetSystemTimePreciseAsFileTime = (pfnGetSystemTimePreciseAsFileTime)GetProcAddress(kernel32, "GetSystemTimePreciseAsFileTime");
         }
diff --git a/src/video/SDL_blit_auto.c b/src/video/SDL_blit_auto.c
index 0964f31f607d6..d4b4e31769ca2 100644
--- a/src/video/SDL_blit_auto.c
+++ b/src/video/SDL_blit_auto.c
@@ -11534,7 +11534,7 @@ SDL_BlitFuncEntry SDL_GeneratedBlitFuncTable[] = {
     { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_ABGR8888, (SDL_COPY_MODULATE_MASK | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGRA8888_ABGR8888_Modulate_Scale },
     { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_ABGR8888, (SDL_COPY_MODULATE_MASK | SDL_COPY_BLEND_MASK), SDL_CPU_ANY, SDL_Blit_BGRA8888_ABGR8888_Modulate_Blend },
     { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_ABGR8888, (SDL_COPY_MODULATE_MASK | SDL_COPY_BLEND_MASK | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGRA8888_ABGR8888_Modulate_Blend_Scale },
-    { 0, 0, 0, 0, NULL }
+    { SDL_PIXELFORMAT_UNKNOWN, SDL_PIXELFORMAT_UNKNOWN, 0, 0, NULL }
 };
 
 /* *INDENT-ON* */ // clang-format on
diff --git a/src/video/SDL_egl.c b/src/video/SDL_egl.c
index 72e97281938cf..23968945b963c 100644
--- a/src/video/SDL_egl.c
+++ b/src/video/SDL_egl.c
@@ -1085,9 +1085,9 @@ SDL_GLContext SDL_EGL_CreateContext(SDL_VideoDevice *_this, EGLSurface egl_surfa
 
     _this->egl_data->egl_swapinterval = 0;
 
-    if (!SDL_EGL_MakeCurrent(_this, egl_surface, egl_context)) {
+    if (!SDL_EGL_MakeCurrent(_this, egl_surface, (SDL_GLContext)egl_context)) {
         // Delete the context
-        SDL_EGL_DestroyContext(_this, egl_context);
+        SDL_EGL_DestroyContext(_this, (SDL_GLContext)egl_context);
         return NULL;
     }
 
diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index e0c118f711a27..caa1f7977759b 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -1371,13 +1371,13 @@ SDL_bool SDL_GetClosestFullscreenDisplayMode(SDL_DisplayID displayID, int w, int
     return true;
 }
 
-static bool DisplayModeChanged(const SDL_DisplayMode *old, const SDL_DisplayMode *new)
+static bool DisplayModeChanged(const SDL_DisplayMode *old_mode, const SDL_DisplayMode *new_mode)
 {
-    return ((old->displayID && old->displayID != new->displayID) ||
-            (old->format && old->format != new->format) ||
-            (old->w && old->h && (old->w != new->w ||old->h != new->h)) ||
-            (old->pixel_density != 0.0f && old->pixel_density != new->pixel_density) ||
-            (old->refresh_rate != 0.0f && old->refresh_rate != new->refresh_rate));
+    return ((old_mode->displayID && old_mode->displayID != new_mode->displayID) ||
+            (old_mode->format && old_mode->format != new_mode->format) ||
+            (old_mode->w && old_mode->h && (old_mode->w != new_mode->w ||old_mode->h != new_mode->h)) ||
+            (old_mode->pixel_density != 0.0f && old_mode->pixel_density != new_mode->pixel_density) ||
+            (old_mode->refresh_rate != 0.0f && old_mode->refresh_rate != new_mode->refresh_rate));
 }
 
 void SDL_SetDesktopDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode *mode)
@@ -1781,7 +1781,7 @@ bool SDL_UpdateFullscreenMode(SDL_Window *window, SDL_FullscreenOp fullscreen, b
 
     // If we are in the process of hiding don't go back to fullscreen
     if (window->is_destroying || window->is_hiding) {
-        fullscreen = false;
+        fullscreen = SDL_FULLSCREEN_OP_LEAVE;
     }
 
     // Get the correct display for this operation
@@ -2132,7 +2132,7 @@ SDL_Window **SDLCALL SDL_GetWindows(int *count)
         ++num_windows;
     }
 
-    SDL_Window **windows = SDL_malloc((num_windows + 1) * sizeof(*windows));
+    SDL_Window **windows = (SDL_Window **)SDL_malloc((num_windows + 1) * sizeof(*windows));
     if (!windows) {
         return NULL;
     }
diff --git a/src/video/offscreen/SDL_offscreenvulkan.c b/src/video/offscreen/SDL_offscreenvulkan.c
index 3d861f0c3e4b8..57c89d7ef57e8 100644
--- a/src/video/offscreen/SDL_offscreenvulkan.c
+++ b/src/video/offscreen/SDL_offscreenvulkan.c
@@ -118,9 +118,9 @@ bool OFFSCREEN_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path)
         }
     }
 
-    _this->vulkan_config.vkGetInstanceProcAddr = (void *)vkGetInstanceProcAddr;
+    _this->vulkan_config.vkGetInstanceProcAddr = (SDL_FunctionPointer)vkGetInstanceProcAddr;
     _this->vulkan_config.vkEnumerateInstanceExtensionProperties =
-        (void *)((PFN_vkGetInstanceProcAddr)_this->vulkan_config.vkGetInstanceProcAddr)(
+        (SDL_FunctionPointer)((PFN_vkGetInstanceProcAddr)_this->vulkan_config.vkGetInstanceProcAddr)(
             VK_NULL_HANDLE, "vkEnumerateInstanceExtensionProperties");
     if (!_this->vulkan_config.vkEnumerateInstanceExtensionProperties) {
         goto fail;
diff --git a/src/video/windows/SDL_windowsgameinput.c b/src/video/windows/SDL_windowsgameinput.c
index ce613fb6a7af5..07b94488bdc40 100644
--- a/src/video/windows/SDL_windowsgameinput.c
+++ b/src/video/windows/SDL_windowsgameinput.c
@@ -536,8 +536,8 @@ bool WIN_UpdateGameInputEnabled(SDL_VideoDevice *_this)
 
     SDL_LockMutex(data->lock);
     {
-        data->enabled_input = (raw_mouse_enabled ? GameInputKindMouse : 0) |
-                             (raw_keyboard_enabled ? GameInputKindKeyboard : 0);
+        data->enabled_input = (raw_mouse_enabled ? GameInputKindMouse : GameInputKindUnknown) |
+                             (raw_keyboard_enabled ? GameInputKindKeyboard : GameInputKindUnknown);
 
         // Reset input if not enabled
         for (int i = 0; i < data->num_devices; ++i) {
diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c
index ffbfb70ad4747..5695fac68fdac 100644
--- a/src/video/windows/SDL_windowswindow.c
+++ b/src/video/windows/SDL_windowswindow.c
@@ -375,7 +375,7 @@ static SDL_WindowEraseBackgroundMode GetEraseBackgroundModeHint(void)
         return SDL_ERASEBACKGROUNDMODE_INITIAL;
     }
 
-    return mode;
+    return (SDL_WindowEraseBackgroundMode)mode;
 }
 
 static bool SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, HWND hwnd, HWND parent)
@@ -904,7 +904,7 @@ bool WIN_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window)
             window->internal->floating_rect_pending = true;
         }
     } else {
-        return SDL_UpdateFullscreenMode(window, true, true);
+        return SDL_UpdateFullscreenMode(window, SDL_FULLSCREEN_OP_ENTER, true);
     }
 
     return true;
@@ -1306,7 +1306,7 @@ SDL_FullscreenResult WIN_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window
     } else {
         BOOL menu;
 
-        WIN_UpdateCornerRoundingForHWND(hwnd, data->windowed_mode_corner_rounding);
+        WIN_UpdateCornerRoundingForHWND(hwnd, (DWM_WINDOW_CORNER_PREFERENCE)data->windowed_mode_corner_rounding);
         WIN_UpdateBorderColorForHWND(hwnd, data->dwma_border_color);
 
         /* Restore window-maximization state, as applicable.
@@ -1896,7 +1896,7 @@ static STDMETHODIMP SDLDropTarget_Drop(SDLDropTarget *target,
                              ". In Drop File for   GlobalLock, format %08x '%s', memory (%lu) %p\n",
                              fetc.cfFormat, format_mime, (unsigned long)bsize, buffer);
                 if (buffer) {
-                    char *text = SDL_malloc(bsize + sizeof(Uint32));
+                    char *text = (char *)SDL_malloc(bsize + sizeof(Uint32));
                     SDL_memcpy((Uint8 *)text, buffer, bsize);
                     SDL_memset((Uint8 *)text + bsize, 0, sizeof(Uint32));
                     char *saveptr = NULL;
@@ -1944,7 +1944,7 @@ static STDMETHODIMP SDLDropTarget_Drop(SDLDropTarget *target,
                              ". In Drop Text for   GlobalLock, format %08x '%s', memory (%lu) %p\n",
                          

(Patch may be truncated, please check the link at the top of this post.)