Parcourir la source

Clang-Tidy fixes (#6725)

(cherry picked from commit 3c501b963dd8f0605a6ce7978882df39ba76f9cd)
Pierre Wendling il y a 2 ans
Parent
commit
d0bbfdbfb8
100 fichiers modifiés avec 898 ajouts et 771 suppressions
  1. 6 6
      include/SDL_audio.h
  2. 2 2
      include/SDL_mutex.h
  3. 3 4
      include/SDL_power.h
  4. 1 1
      include/SDL_surface.h
  5. 2 2
      src/SDL_assert.c
  6. 1 1
      src/SDL_error.c
  7. 13 7
      src/SDL_log.c
  8. 40 19
      src/audio/SDL_audio.c
  9. 23 22
      src/audio/SDL_audiocvt.c
  10. 7 4
      src/audio/SDL_audiodev.c
  11. 1 1
      src/audio/SDL_audiotypecvt.c
  12. 4 4
      src/audio/SDL_wave.c
  13. 11 8
      src/audio/alsa/SDL_alsa_audio.c
  14. 26 14
      src/audio/coreaudio/SDL_coreaudio.m
  15. 2 2
      src/audio/dsp/SDL_dspaudio.c
  16. 11 3
      src/audio/jack/SDL_jackaudio.c
  17. 12 11
      src/audio/pipewire/SDL_pipewire.c
  18. 19 16
      src/audio/sndio/SDL_sndioaudio.c
  19. 0 1
      src/core/android/SDL_android.c
  20. 6 6
      src/core/linux/SDL_evdev.c
  21. 4 4
      src/core/linux/SDL_evdev_capabilities.c
  22. 4 4
      src/core/linux/SDL_evdev_capabilities.h
  23. 53 45
      src/core/linux/SDL_evdev_kbd.c
  24. 2 2
      src/core/linux/SDL_fcitx.c
  25. 5 5
      src/core/linux/SDL_ibus.c
  26. 4 4
      src/core/windows/SDL_windows.c
  27. 90 90
      src/events/SDL_events.c
  28. 4 3
      src/events/SDL_keyboard.c
  29. 1 1
      src/events/SDL_keyboard_c.h
  30. 1 1
      src/events/SDL_mouse.c
  31. 1 1
      src/events/SDL_quit.c
  32. 1 1
      src/file/SDL_rwops.c
  33. 1 1
      src/file/cocoa/SDL_rwopsbundlesupport.m
  34. 2 2
      src/filesystem/unix/SDL_sysfilesystem.c
  35. 5 4
      src/haptic/SDL_haptic.c
  36. 1 4
      src/haptic/android/SDL_syshaptic.c
  37. 2 1
      src/haptic/darwin/SDL_syshaptic.c
  38. 3 4
      src/haptic/linux/SDL_syshaptic.c
  39. 21 20
      src/haptic/windows/SDL_dinputhaptic.c
  40. 2 2
      src/haptic/windows/SDL_xinputhaptic.c
  41. 36 23
      src/hidapi/SDL_hidapi.c
  42. 39 37
      src/joystick/SDL_gamecontroller.c
  43. 3 3
      src/joystick/SDL_joystick.c
  44. 1 4
      src/joystick/darwin/SDL_iokitjoystick.c
  45. 1 1
      src/joystick/hidapi/SDL_hidapi_gamecube.c
  46. 6 5
      src/joystick/hidapi/SDL_hidapi_ps3.c
  47. 10 10
      src/joystick/hidapi/SDL_hidapi_ps4.c
  48. 6 6
      src/joystick/hidapi/SDL_hidapi_ps5.c
  49. 1 1
      src/joystick/hidapi/SDL_hidapi_shield.c
  50. 16 11
      src/joystick/hidapi/SDL_hidapi_steam.c
  51. 12 11
      src/joystick/hidapi/SDL_hidapi_switch.c
  52. 5 5
      src/joystick/hidapi/SDL_hidapi_xboxone.c
  53. 4 6
      src/joystick/hidapi/SDL_hidapijoystick.c
  54. 16 15
      src/joystick/iphoneos/SDL_mfijoystick.m
  55. 3 3
      src/joystick/linux/SDL_sysjoystick.c
  56. 0 1
      src/joystick/virtual/SDL_virtualjoystick.c
  57. 7 7
      src/joystick/windows/SDL_dinputjoystick.c
  58. 4 4
      src/joystick/windows/SDL_rawinputjoystick.c
  59. 4 2
      src/joystick/windows/SDL_windows_gaming_input.c
  60. 3 3
      src/joystick/windows/SDL_windowsjoystick.c
  61. 14 14
      src/joystick/windows/SDL_xinputjoystick.c
  62. 2 1
      src/locale/macosx/SDL_syslocale.m
  63. 1 1
      src/locale/windows/SDL_syslocale.c
  64. 2 2
      src/main/windows/SDL_windows_main.c
  65. 0 2
      src/misc/SDL_url.c
  66. 1 1
      src/power/linux/SDL_syspower.c
  67. 11 9
      src/render/SDL_render.c
  68. 4 4
      src/render/SDL_yuv_sw.c
  69. 15 14
      src/render/direct3d/SDL_render_d3d.c
  70. 8 8
      src/render/direct3d11/SDL_render_d3d11.c
  71. 9 9
      src/render/direct3d12/SDL_render_d3d12.c
  72. 1 1
      src/render/metal/SDL_render_metal.m
  73. 4 7
      src/render/opengl/SDL_render_gl.c
  74. 1 1
      src/render/opengl/SDL_shaders_gl.c
  75. 4 7
      src/render/opengles2/SDL_render_gles2.c
  76. 4 4
      src/render/software/SDL_render_sw.c
  77. 1 1
      src/render/software/SDL_rotate.c
  78. 17 10
      src/render/software/SDL_triangle.c
  79. 4 0
      src/stdlib/SDL_mslibc.c
  80. 12 9
      src/stdlib/SDL_string.c
  81. 3 3
      src/test/SDL_test_assert.c
  82. 50 50
      src/test/SDL_test_common.c
  83. 6 4
      src/test/SDL_test_compare.c
  84. 1 1
      src/test/SDL_test_font.c
  85. 3 3
      src/test/SDL_test_harness.c
  86. 9 4
      src/test/SDL_test_log.c
  87. 5 5
      src/test/SDL_test_memory.c
  88. 5 5
      src/thread/SDL_thread.c
  89. 1 1
      src/thread/pthread/SDL_syscond.c
  90. 37 23
      src/video/SDL_RLEaccel.c
  91. 1 1
      src/video/SDL_blit.c
  92. 8 4
      src/video/SDL_blit_A.c
  93. 3 3
      src/video/SDL_blit_N.c
  94. 35 34
      src/video/SDL_bmp.c
  95. 1 1
      src/video/SDL_egl.c
  96. 1 1
      src/video/SDL_fillrect.c
  97. 8 4
      src/video/SDL_pixels.c
  98. 15 16
      src/video/SDL_shape.c
  99. 15 10
      src/video/SDL_video.c
  100. 2 2
      src/video/SDL_vulkan_utils.c

+ 6 - 6
include/SDL_audio.h

@@ -1008,12 +1008,12 @@ typedef struct _SDL_AudioStream SDL_AudioStream;
  * \sa SDL_AudioStreamClear
  * \sa SDL_FreeAudioStream
  */
-extern DECLSPEC SDL_AudioStream * SDLCALL SDL_NewAudioStream(const SDL_AudioFormat src_format,
-                                           const Uint8 src_channels,
-                                           const int src_rate,
-                                           const SDL_AudioFormat dst_format,
-                                           const Uint8 dst_channels,
-                                           const int dst_rate);
+extern DECLSPEC SDL_AudioStream *SDLCALL SDL_NewAudioStream(SDL_AudioFormat src_format,
+                                                            Uint8 src_channels,
+                                                            int src_rate,
+                                                            SDL_AudioFormat dst_format,
+                                                            Uint8 dst_channels,
+                                                            int dst_rate);
 
 /**
  * Add data to be converted/resampled to the stream.

+ 2 - 2
include/SDL_mutex.h

@@ -276,7 +276,7 @@ extern DECLSPEC int SDLCALL SDL_SemTryWait(SDL_sem * sem);
  * successful it will atomically decrement the semaphore value.
  *
  * \param sem the semaphore to wait on
- * \param ms the length of the timeout, in milliseconds
+ * \param timeout the length of the timeout, in milliseconds
  * \returns 0 if the wait succeeds, `SDL_MUTEX_TIMEDOUT` if the wait does not
  *          succeed in the allotted time, or a negative error code on failure;
  *          call SDL_GetError() for more information.
@@ -290,7 +290,7 @@ extern DECLSPEC int SDLCALL SDL_SemTryWait(SDL_sem * sem);
  * \sa SDL_SemValue
  * \sa SDL_SemWait
  */
-extern DECLSPEC int SDLCALL SDL_SemWaitTimeout(SDL_sem * sem, Uint32 ms);
+extern DECLSPEC int SDLCALL SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout);
 
 /**
  * Atomically increment a semaphore's value and wake waiting threads.

+ 3 - 4
include/SDL_power.h

@@ -48,7 +48,6 @@ typedef enum
     SDL_POWERSTATE_CHARGED       /**< Plugged in, battery charged */
 } SDL_PowerState;
 
-
 /**
  * Get the current power supply details.
  *
@@ -65,17 +64,17 @@ typedef enum
  * It's possible a platform can only report battery percentage or time left
  * but not both.
  *
- * \param secs seconds of battery life left, you can pass a NULL here if you
+ * \param seconds seconds of battery life left, you can pass a NULL here if you
  *             don't care, will return -1 if we can't determine a value, or
  *             we're not running on a battery
- * \param pct percentage of battery life left, between 0 and 100, you can pass
+ * \param percent percentage of battery life left, between 0 and 100, you can pass
  *            a NULL here if you don't care, will return -1 if we can't
  *            determine a value, or we're not running on a battery
  * \returns an SDL_PowerState enum representing the current battery state.
  *
  * \since This function is available since SDL 2.0.0.
  */
-extern DECLSPEC SDL_PowerState SDLCALL SDL_GetPowerInfo(int *secs, int *pct);
+extern DECLSPEC SDL_PowerState SDLCALL SDL_GetPowerInfo(int *seconds, int *percent);
 
 /* Ends C function definitions when using C++ */
 #ifdef __cplusplus

+ 1 - 1
include/SDL_surface.h

@@ -683,7 +683,7 @@ extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurface
  * it might be easier to call but it doesn't have access to palette
  * information for the destination surface, in case that would be important.
  *
- * \param src the existing SDL_Surface structure to convert
+ * \param surface the existing SDL_Surface structure to convert
  * \param pixel_format the SDL_PixelFormatEnum that the new surface is
  *                     optimized for
  * \param flags the flags are unused and should be set to 0; this is a

+ 2 - 2
src/SDL_assert.c

@@ -288,8 +288,8 @@ static SDL_assert_state SDLCALL SDL_PromptAssertion(const SDL_assert_data *data,
         /* this is a little hacky. */
         for (;;) {
             char buf[32];
-            fprintf(stderr, "Abort/Break/Retry/Ignore/AlwaysIgnore? [abriA] : ");
-            fflush(stderr);
+            (void)fprintf(stderr, "Abort/Break/Retry/Ignore/AlwaysIgnore? [abriA] : ");
+            (void)fflush(stderr);
             if (fgets(buf, sizeof(buf), stdin) == NULL) {
                 break;
             }

+ 1 - 1
src/SDL_error.c

@@ -46,7 +46,7 @@ int SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
                 error->str = str;
                 error->len = len;
                 va_start(ap, fmt);
-                SDL_vsnprintf(error->str, error->len, fmt, ap);
+                (void)SDL_vsnprintf(error->str, error->len, fmt, ap);
                 va_end(ap);
             }
         }

+ 13 - 7
src/SDL_log.c

@@ -415,7 +415,7 @@ static void SDLCALL SDL_LogOutput(void *userdata, int category, SDL_LogPriority
 
         length = SDL_strlen(SDL_priority_prefixes[priority]) + 2 + SDL_strlen(message) + 1 + 1 + 1;
         output = SDL_small_alloc(char, length, &isstack);
-        SDL_snprintf(output, length, "%s: %s\r\n", SDL_priority_prefixes[priority], message);
+        (void)SDL_snprintf(output, length, "%s: %s\r\n", SDL_priority_prefixes[priority], message);
         tstr = WIN_UTF8ToString(output);
 
         /* Output to debugger */
@@ -460,22 +460,28 @@ static void SDLCALL SDL_LogOutput(void *userdata, int category, SDL_LogPriority
     {
         FILE *pFile;
         pFile = fopen("SDL_Log.txt", "a");
-        fprintf(pFile, "%s: %s\n", SDL_priority_prefixes[priority], message);
-        fclose(pFile);
+        if (pFile != NULL) {
+            (void)fprintf(pFile, "%s: %s\n", SDL_priority_prefixes[priority], message);
+            (void)fclose(pFile);
+        }
     }
 #elif defined(__VITA__)
     {
         FILE *pFile;
         pFile = fopen("ux0:/data/SDL_Log.txt", "a");
-        fprintf(pFile, "%s: %s\n", SDL_priority_prefixes[priority], message);
-        fclose(pFile);
+        if (pFile != NULL) {
+            (void)fprintf(pFile, "%s: %s\n", SDL_priority_prefixes[priority], message);
+            (void)fclose(pFile);
+        }
     }
 #elif defined(__3DS__)
     {
         FILE *pFile;
         pFile = fopen("sdmc:/3ds/SDL_Log.txt", "a");
-        fprintf(pFile, "%s: %s\n", SDL_priority_prefixes[priority], message);
-        fclose(pFile);
+        if (pFile != NULL) {
+            (void)fprintf(pFile, "%s: %s\n", SDL_priority_prefixes[priority], message);
+            (void)fclose(pFile);
+        }
     }
 #endif
 #if HAVE_STDIO_H && \

+ 40 - 19
src/audio/SDL_audio.c

@@ -394,7 +394,7 @@ static int add_audio_device(const char *name, SDL_AudioSpec *spec, void *handle,
             return SDL_OutOfMemory();
         }
 
-        SDL_snprintf(replacement, len, "%s (%d)", name, dupenum + 1);
+        (void)SDL_snprintf(replacement, len, "%s (%d)", name, dupenum + 1);
         item->dupenum = dupenum;
         item->name = replacement;
     }
@@ -658,6 +658,10 @@ void SDL_ClearQueuedAudio(SDL_AudioDeviceID devid)
     current_audio.impl.UnlockDevice(device);
 }
 
+#if SDL_AUDIO_DRIVER_ANDROID
+extern void Android_JNI_AudioSetThreadPriority(int, int);
+#endif
+
 /* The general mixing thread function */
 static int SDLCALL SDL_RunAudio(void *devicep)
 {
@@ -672,7 +676,6 @@ static int SDLCALL SDL_RunAudio(void *devicep)
 #if SDL_AUDIO_DRIVER_ANDROID
     {
         /* Set thread priority to THREAD_PRIORITY_AUDIO */
-        extern void Android_JNI_AudioSetThreadPriority(int, int);
         Android_JNI_AudioSetThreadPriority(device->iscapture, device->id);
     }
 #else
@@ -773,7 +776,6 @@ static int SDLCALL SDL_CaptureAudio(void *devicep)
 #if SDL_AUDIO_DRIVER_ANDROID
     {
         /* Set thread priority to THREAD_PRIORITY_AUDIO */
-        extern void Android_JNI_AudioSetThreadPriority(int, int);
         Android_JNI_AudioSetThreadPriority(device->iscapture, device->id);
     }
 #else
@@ -1187,6 +1189,19 @@ static void close_audio_device(SDL_AudioDevice *device)
     SDL_free(device);
 }
 
+static Uint16
+GetDefaultSamplesFromFreq(int freq)
+{
+    /* Pick a default of ~46 ms at desired frequency */
+    /* !!! FIXME: remove this when the non-Po2 resampling is in. */
+    const Uint16 max_sample = (freq / 1000) * 46;
+    Uint16 current_sample = 1;
+    while (current_sample < max_sample) {
+        current_sample *= 2;
+    }
+    return current_sample;
+}
+
 /*
  * Sanity check desired AudioSpec for SDL_OpenAudio() in (orig).
  *  Fills in a sanitized copy in (prepared).
@@ -1197,23 +1212,33 @@ static int prepare_audiospec(const SDL_AudioSpec *orig, SDL_AudioSpec *prepared)
     SDL_copyp(prepared, orig);
 
     if (orig->freq == 0) {
+        static const int DEFAULT_FREQ = 22050;
         const char *env = SDL_getenv("SDL_AUDIO_FREQUENCY");
-        if ((!env) || ((prepared->freq = SDL_atoi(env)) == 0)) {
-            prepared->freq = 22050; /* a reasonable default */
+        if (env != NULL) {
+            int freq = SDL_atoi(env);
+            prepared->freq = freq != 0 ? freq : DEFAULT_FREQ;
+        } else {
+            prepared->freq = DEFAULT_FREQ;
         }
     }
 
     if (orig->format == 0) {
         const char *env = SDL_getenv("SDL_AUDIO_FORMAT");
-        if ((!env) || ((prepared->format = SDL_ParseAudioFormat(env)) == 0)) {
-            prepared->format = AUDIO_S16; /* a reasonable default */
+        if (env != NULL) {
+            const SDL_AudioFormat format = SDL_ParseAudioFormat(env);
+            prepared->format = format != 0 ? format : AUDIO_S16;
+        } else {
+            prepared->format = AUDIO_S16;
         }
     }
 
     if (orig->channels == 0) {
         const char *env = SDL_getenv("SDL_AUDIO_CHANNELS");
-        if ((!env) || ((prepared->channels = (Uint8)SDL_atoi(env)) == 0)) {
-            prepared->channels = 2; /* a reasonable default */
+        if (env != NULL) {
+            Uint8 channels = (Uint8)SDL_atoi(env);
+            prepared->channels = channels != 0 ? channels : 2;
+        } else {
+            prepared->channels = 2;
         }
     } else if (orig->channels > 8) {
         SDL_SetError("Unsupported number of audio channels.");
@@ -1222,15 +1247,11 @@ static int prepare_audiospec(const SDL_AudioSpec *orig, SDL_AudioSpec *prepared)
 
     if (orig->samples == 0) {
         const char *env = SDL_getenv("SDL_AUDIO_SAMPLES");
-        if ((!env) || ((prepared->samples = (Uint16)SDL_atoi(env)) == 0)) {
-            /* Pick a default of ~46 ms at desired frequency */
-            /* !!! FIXME: remove this when the non-Po2 resampling is in. */
-            const int samples = (prepared->freq / 1000) * 46;
-            int power2 = 1;
-            while (power2 < samples) {
-                power2 *= 2;
-            }
-            prepared->samples = power2;
+        if (env != NULL) {
+            Uint16 samples = (Uint16)SDL_atoi(env);
+            prepared->samples = samples != 0 ? samples : GetDefaultSamplesFromFreq(prepared->freq);
+        } else {
+            prepared->samples = GetDefaultSamplesFromFreq(prepared->freq);
         }
     }
 
@@ -1488,7 +1509,7 @@ static SDL_AudioDeviceID open_audio_device(const char *devname, int iscapture,
         const size_t stacksize = is_internal_thread ? 64 * 1024 : 0;
         char threadname[64];
 
-        SDL_snprintf(threadname, sizeof(threadname), "SDLAudio%c%d", (iscapture) ? 'C' : 'P', (int)device->id);
+        (void)SDL_snprintf(threadname, sizeof threadname, "SDLAudio%c%" SDL_PRIu32, (iscapture) ? 'C' : 'P', device->id);
         device->thread = SDL_CreateThreadInternal(iscapture ? SDL_CaptureAudio : SDL_RunAudio, threadname, stacksize, device);
 
         if (device->thread == NULL) {

+ 23 - 22
src/audio/SDL_audiocvt.c

@@ -208,7 +208,7 @@ static int SDL_ResampleAudio(const int chans, const int inrate, const int outrat
     const int paddinglen = ResamplerPadding(inrate, outrate);
     const int framelen = chans * (int)sizeof(float);
     const int inframes = inbuflen / framelen;
-    const int wantedoutframes = (int)((inbuflen / framelen) * ratio); /* outbuflen isn't total to write, it's total available. */
+    const int wantedoutframes = (int)(inframes * ratio); /* outbuflen isn't total to write, it's total available. */
     const int maxoutframes = outbuflen / framelen;
     const int outframes = SDL_min(wantedoutframes, maxoutframes);
     ResampleFloatType outtime = 0.0f;
@@ -233,7 +233,7 @@ static int SDL_ResampleAudio(const int chans, const int inrate, const int outrat
                 const int srcframe = srcindex - j;
                 /* !!! FIXME: we can bubble this conditional out of here by doing a pre loop. */
                 const float insample = (srcframe < 0) ? lpadding[((paddinglen + srcframe) * chans) + chan] : inbuf[(srcframe * chans) + chan];
-                outsample += (float)(insample * (ResamplerFilter[filterindex1 + (j * RESAMPLER_SAMPLES_PER_ZERO_CROSSING)] + (interpolation1 * ResamplerFilterDifference[filterindex1 + (j * RESAMPLER_SAMPLES_PER_ZERO_CROSSING)])));
+                outsample += (insample * (ResamplerFilter[filterindex1 + (j * RESAMPLER_SAMPLES_PER_ZERO_CROSSING)] + (interpolation1 * ResamplerFilterDifference[filterindex1 + (j * RESAMPLER_SAMPLES_PER_ZERO_CROSSING)])));
             }
 
             /* Do the right wing! */
@@ -242,7 +242,7 @@ static int SDL_ResampleAudio(const int chans, const int inrate, const int outrat
                 const int srcframe = srcindex + 1 + j;
                 /* !!! FIXME: we can bubble this conditional out of here by doing a post loop. */
                 const float insample = (srcframe >= inframes) ? rpadding[((srcframe - inframes) * chans) + chan] : inbuf[(srcframe * chans) + chan];
-                outsample += (float)(insample * (ResamplerFilter[filterindex2 + jsamples] + (interpolation2 * ResamplerFilterDifference[filterindex2 + jsamples])));
+                outsample += (insample * (ResamplerFilter[filterindex2 + jsamples] + (interpolation2 * ResamplerFilterDifference[filterindex2 + jsamples])));
             }
 
             *(dst++) = outsample;
@@ -316,7 +316,7 @@ static void SDLCALL SDL_Convert_Byteswap(SDL_AudioCVT *cvt, SDL_AudioFormat form
     }
 }
 
-static int SDL_AddAudioCVTFilter(SDL_AudioCVT *cvt, const SDL_AudioFilter filter)
+static int SDL_AddAudioCVTFilter(SDL_AudioCVT *cvt, SDL_AudioFilter filter)
 {
     if (cvt->filter_index >= SDL_AUDIOCVT_MAX_FILTERS) {
         return SDL_SetError("Too many filters needed for conversion, exceeded maximum of %d", SDL_AUDIOCVT_MAX_FILTERS);
@@ -376,7 +376,8 @@ static int SDL_BuildAudioTypeCVTToFloat(SDL_AudioCVT *cvt, const SDL_AudioFormat
             cvt->len_mult *= mult;
             cvt->len_ratio *= mult;
         } else if (src_bitsize > dst_bitsize) {
-            cvt->len_ratio /= (src_bitsize / dst_bitsize);
+            const int div = (src_bitsize / dst_bitsize);
+            cvt->len_ratio /= div;
         }
 
         retval = 1; /* added a converter. */
@@ -674,8 +675,8 @@ static SDL_bool SDL_SupportedChannelCount(const int channels)
 */
 
 int SDL_BuildAudioCVT(SDL_AudioCVT *cvt,
-                      SDL_AudioFormat src_fmt, Uint8 src_channels, int src_rate,
-                      SDL_AudioFormat dst_fmt, Uint8 dst_channels, int dst_rate)
+                      SDL_AudioFormat src_format, Uint8 src_channels, int src_rate,
+                      SDL_AudioFormat dst_format, Uint8 dst_channels, int dst_rate)
 {
     SDL_AudioFilter channel_converter = NULL;
 
@@ -687,10 +688,10 @@ int SDL_BuildAudioCVT(SDL_AudioCVT *cvt,
     /* Make sure we zero out the audio conversion before error checking */
     SDL_zerop(cvt);
 
-    if (!SDL_SupportedAudioFormat(src_fmt)) {
+    if (!SDL_SupportedAudioFormat(src_format)) {
         return SDL_SetError("Invalid source format");
     }
-    if (!SDL_SupportedAudioFormat(dst_fmt)) {
+    if (!SDL_SupportedAudioFormat(dst_format)) {
         return SDL_SetError("Invalid destination format");
     }
     if (!SDL_SupportedChannelCount(src_channels)) {
@@ -714,12 +715,12 @@ int SDL_BuildAudioCVT(SDL_AudioCVT *cvt,
 
 #if DEBUG_CONVERT
     SDL_Log("SDL_AUDIO_CONVERT: Build format %04x->%04x, channels %u->%u, rate %d->%d\n",
-            src_fmt, dst_fmt, src_channels, dst_channels, src_rate, dst_rate);
+            src_format, dst_format, src_channels, dst_channels, src_rate, dst_rate);
 #endif
 
     /* Start off with no conversion necessary */
-    cvt->src_format = src_fmt;
-    cvt->dst_format = dst_fmt;
+    cvt->src_format = src_format;
+    cvt->dst_format = dst_format;
     cvt->needed = 0;
     cvt->filter_index = 0;
     SDL_zeroa(cvt->filters);
@@ -746,13 +747,13 @@ int SDL_BuildAudioCVT(SDL_AudioCVT *cvt,
 
     /* see if we can skip float conversion entirely. */
     if (src_rate == dst_rate && src_channels == dst_channels) {
-        if (src_fmt == dst_fmt) {
+        if (src_format == dst_format) {
             return 0;
         }
 
         /* just a byteswap needed? */
-        if ((src_fmt & ~SDL_AUDIO_MASK_ENDIAN) == (dst_fmt & ~SDL_AUDIO_MASK_ENDIAN)) {
-            if (SDL_AUDIO_BITSIZE(dst_fmt) == 8) {
+        if ((src_format & ~SDL_AUDIO_MASK_ENDIAN) == (dst_format & ~SDL_AUDIO_MASK_ENDIAN)) {
+            if (SDL_AUDIO_BITSIZE(dst_format) == 8) {
                 return 0;
             }
             if (SDL_AddAudioCVTFilter(cvt, SDL_Convert_Byteswap) < 0) {
@@ -764,7 +765,7 @@ int SDL_BuildAudioCVT(SDL_AudioCVT *cvt,
     }
 
     /* Convert data types, if necessary. Updates (cvt). */
-    if (SDL_BuildAudioTypeCVTToFloat(cvt, src_fmt) < 0) {
+    if (SDL_BuildAudioTypeCVTToFloat(cvt, src_format) < 0) {
         return -1; /* shouldn't happen, but just in case... */
     }
 
@@ -820,7 +821,7 @@ int SDL_BuildAudioCVT(SDL_AudioCVT *cvt,
     }
 
     /* Move to final data type. */
-    if (SDL_BuildAudioTypeCVTFromFloat(cvt, dst_fmt) < 0) {
+    if (SDL_BuildAudioTypeCVTFromFloat(cvt, dst_format) < 0) {
         return -1; /* shouldn't happen, but just in case... */
     }
 
@@ -862,7 +863,7 @@ struct _SDL_AudioStream
     SDL_CleanupAudioStreamResamplerFunc cleanup_resampler_func;
 };
 
-static Uint8 *EnsureStreamBufferSize(SDL_AudioStream *stream, const int newlen)
+static Uint8 *EnsureStreamBufferSize(SDL_AudioStream *stream, int newlen)
 {
     Uint8 *ptr;
     size_t offset;
@@ -870,7 +871,7 @@ static Uint8 *EnsureStreamBufferSize(SDL_AudioStream *stream, const int newlen)
     if (stream->work_buffer_len >= newlen) {
         ptr = stream->work_buffer_base;
     } else {
-        ptr = (Uint8 *)SDL_realloc(stream->work_buffer_base, newlen + 32);
+        ptr = (Uint8 *)SDL_realloc(stream->work_buffer_base, (size_t)newlen + 32);
         if (ptr == NULL) {
             SDL_OutOfMemory();
             return NULL;
@@ -1006,7 +1007,7 @@ SDL_NewAudioStream(const SDL_AudioFormat src_format,
                    const Uint8 dst_channels,
                    const int dst_rate)
 {
-    const int packetlen = 4096; /* !!! FIXME: good enough for now. */
+    int packetlen = 4096; /* !!! FIXME: good enough for now. */
     Uint8 pre_resample_channels;
     SDL_AudioStream *retval;
 
@@ -1092,7 +1093,7 @@ SDL_NewAudioStream(const SDL_AudioFormat src_format,
         }
     }
 
-    retval->queue = SDL_NewDataQueue(packetlen, packetlen * 2);
+    retval->queue = SDL_NewDataQueue(packetlen, (size_t)packetlen * 2);
     if (!retval->queue) {
         SDL_FreeAudioStream(retval);
         return NULL; /* SDL_NewDataQueue should have called SDL_SetError. */
@@ -1384,7 +1385,7 @@ void SDL_AudioStreamClear(SDL_AudioStream *stream)
     if (stream == NULL) {
         SDL_InvalidParamError("stream");
     } else {
-        SDL_ClearDataQueue(stream->queue, stream->packetlen * 2);
+        SDL_ClearDataQueue(stream->queue, (size_t)stream->packetlen * 2);
         if (stream->reset_resampler_func) {
             stream->reset_resampler_func(stream);
         }

+ 7 - 4
src/audio/SDL_audiodev.c

@@ -86,8 +86,11 @@ static void SDL_EnumUnixAudioDevices_Internal(const int iscapture, const int cla
     }
 
     /* Figure out what our audio device is */
-    if (((audiodev = SDL_getenv("SDL_PATH_DSP")) == NULL) &&
-        ((audiodev = SDL_getenv("AUDIODEV")) == NULL)) {
+    audiodev = SDL_getenv("SDL_PATH_DSP");
+    if (audiodev == NULL) {
+        audiodev = SDL_getenv("AUDIODEV");
+    }
+    if (audiodev == NULL) {
         if (classic) {
             audiodev = _PATH_DEV_AUDIO;
         } else {
@@ -106,8 +109,8 @@ static void SDL_EnumUnixAudioDevices_Internal(const int iscapture, const int cla
     if (SDL_strlen(audiodev) < (sizeof(audiopath) - 3)) {
         int instance = 0;
         while (instance <= 64) {
-            SDL_snprintf(audiopath, SDL_arraysize(audiopath),
-                         "%s%d", audiodev, instance);
+            (void)SDL_snprintf(audiopath, SDL_arraysize(audiopath),
+                               "%s%d", audiodev, instance);
             instance++;
             test_device(iscapture, audiopath, flags, test);
         }

+ 1 - 1
src/audio/SDL_audiotypecvt.c

@@ -1198,7 +1198,7 @@ static void SDLCALL SDL_Convert_F32_to_S8_NEON(SDL_AudioCVT *cvt, SDL_AudioForma
 static void SDLCALL SDL_Convert_F32_to_U8_NEON(SDL_AudioCVT *cvt, SDL_AudioFormat format)
 {
     const float *src = (const float *)cvt->buf;
-    Uint8 *dst = (Uint8 *)cvt->buf;
+    Uint8 *dst = cvt->buf;
     int i;
 
     LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_U8 (using NEON)");

+ 4 - 4
src/audio/SDL_wave.c

@@ -549,20 +549,20 @@ static int MS_ADPCM_DecodeBlockHeader(ADPCM_DecoderState *state)
         cstate[c].coeff2 = ddata->coeff[coeffindex * 2 + 1];
 
         /* Initial delta value. */
-        o = channels + c * 2;
+        o = (size_t)channels + c * 2;
         cstate[c].delta = state->block.data[o] | ((Uint16)state->block.data[o + 1] << 8);
 
         /* Load the samples from the header. Interestingly, the sample later in
          * the output stream comes first.
          */
-        o = channels * 3 + c * 2;
+        o = (size_t)channels * 3 + c * 2;
         sample = state->block.data[o] | ((Sint32)state->block.data[o + 1] << 8);
         if (sample >= 0x8000) {
             sample -= 0x10000;
         }
         state->output.data[state->output.pos + channels] = (Sint16)sample;
 
-        o = channels * 5 + c * 2;
+        o = (size_t)channels * 5 + c * 2;
         sample = state->block.data[o] | ((Sint32)state->block.data[o + 1] << 8);
         if (sample >= 0x8000) {
             sample -= 0x10000;
@@ -965,7 +965,7 @@ static int IMA_ADPCM_DecodeBlockData(ADPCM_DecoderState *state)
     size_t i;
     int retval = 0;
     const Uint32 channels = state->channels;
-    const size_t subblockframesize = channels * 4;
+    const size_t subblockframesize = (size_t)channels * 4;
     Uint64 bytesrequired;
     Uint32 c;
 

+ 11 - 8
src/audio/alsa/SDL_alsa_audio.c

@@ -379,8 +379,9 @@ static void ALSA_PlayDevice(_THIS)
             status = ALSA_snd_pcm_recover(this->hidden->pcm_handle, status, 0);
             if (status < 0) {
                 /* Hmm, not much we can do - abort */
-                fprintf(stderr, "ALSA write failed (unrecoverable): %s\n",
-                        ALSA_snd_strerror(status));
+                SDL_LogError(SDL_LOG_CATEGORY_AUDIO,
+                             "ALSA write failed (unrecoverable): %s\n",
+                             ALSA_snd_strerror(status));
                 SDL_OpenedAudioDeviceDisconnected(this);
                 return;
             }
@@ -427,8 +428,9 @@ static int ALSA_CaptureFromDevice(_THIS, void *buffer, int buflen)
             status = ALSA_snd_pcm_recover(this->hidden->pcm_handle, status, 0);
             if (status < 0) {
                 /* Hmm, not much we can do - abort */
-                fprintf(stderr, "ALSA read failed (unrecoverable): %s\n",
-                        ALSA_snd_strerror(status));
+                SDL_LogError(SDL_LOG_CATEGORY_AUDIO,
+                             "ALSA read failed (unrecoverable): %s\n",
+                             ALSA_snd_strerror(status));
                 return -1;
             }
             continue;
@@ -511,9 +513,9 @@ static int ALSA_set_buffer_size(_THIS, snd_pcm_hw_params_t *params)
 
         ALSA_snd_pcm_hw_params_get_buffer_size(hwparams, &bufsize);
 
-        fprintf(stderr,
-                "ALSA: period size = %ld, periods = %u, buffer size = %lu\n",
-                persize, periods, bufsize);
+        SDL_LogError(SDL_LOG_CATEGORY_AUDIO,
+                     "ALSA: period size = %ld, periods = %u, buffer size = %lu\n",
+                     persize, periods, bufsize);
     }
 
     return 0;
@@ -739,7 +741,8 @@ static void add_device(const int iscapture, const char *name, void *hint, ALSA_D
     /* some strings have newlines, like "HDA NVidia, HDMI 0\nHDMI Audio Output".
        just chop the extra lines off, this seems to get a reasonable device
        name without extra details. */
-    if ((ptr = SDL_strchr(desc, '\n')) != NULL) {
+    ptr = SDL_strchr(desc, '\n');
+    if (ptr != NULL) {
         *ptr = '\0';
     }
 

+ 26 - 14
src/audio/coreaudio/SDL_coreaudio.m

@@ -102,17 +102,20 @@ static void build_device_list(int iscapture, addDevFn addfn, void *addfndata)
 
     result = AudioObjectGetPropertyDataSize(kAudioObjectSystemObject,
                                             &devlist_address, 0, NULL, &size);
-    if (result != kAudioHardwareNoError)
+    if (result != kAudioHardwareNoError) {
         return;
+    }
 
     devs = (AudioDeviceID *)alloca(size);
-    if (devs == NULL)
+    if (devs == NULL) {
         return;
+    }
 
     result = AudioObjectGetPropertyData(kAudioObjectSystemObject,
                                         &devlist_address, 0, NULL, &size, devs);
-    if (result != kAudioHardwareNoError)
+    if (result != kAudioHardwareNoError) {
         return;
+    }
 
     max = size / sizeof(AudioDeviceID);
     for (i = 0; i < max; i++) {
@@ -141,12 +144,14 @@ static void build_device_list(int iscapture, addDevFn addfn, void *addfndata)
         };
 
         result = AudioObjectGetPropertyDataSize(dev, &addr, 0, NULL, &size);
-        if (result != noErr)
+        if (result != noErr) {
             continue;
+        }
 
         buflist = (AudioBufferList *)SDL_malloc(size);
-        if (buflist == NULL)
+        if (buflist == NULL) {
             continue;
+        }
 
         result = AudioObjectGetPropertyData(dev, &addr, 0, NULL,
                                             &size, buflist);
@@ -161,8 +166,9 @@ static void build_device_list(int iscapture, addDevFn addfn, void *addfndata)
 
         SDL_free(buflist);
 
-        if (spec.channels == 0)
+        if (spec.channels == 0) {
             continue;
+        }
 
         size = sizeof(sampleRate);
         result = AudioObjectGetPropertyData(dev, &freqaddr, 0, NULL, &size, &sampleRate);
@@ -172,8 +178,9 @@ static void build_device_list(int iscapture, addDevFn addfn, void *addfndata)
 
         size = sizeof(CFStringRef);
         result = AudioObjectGetPropertyData(dev, &nameaddr, 0, NULL, &size, &cfstr);
-        if (result != kAudioHardwareNoError)
+        if (result != kAudioHardwareNoError) {
             continue;
+        }
 
         len = CFStringGetMaximumSizeForEncoding(CFStringGetLength(cfstr),
                                                 kCFStringEncodingUTF8);
@@ -540,8 +547,9 @@ static void outputCallback(void *inUserData, AudioQueueRef inAQ, AudioQueueBuffe
             if (SDL_AudioStreamAvailable(this->stream) > 0) {
                 int got;
                 UInt32 len = SDL_AudioStreamAvailable(this->stream);
-                if (len > remaining)
+                if (len > remaining) {
                     len = remaining;
+                }
                 got = SDL_AudioStreamGet(this->stream, ptr, len);
                 SDL_assert((got < 0) || (got == len));
                 if (got != len) {
@@ -985,7 +993,7 @@ static int audioqueue_thread(void *arg)
     }
 
     if (!this->iscapture) { /* Drain off any pending playback. */
-        const CFTimeInterval secs = (((this->spec.size / (SDL_AUDIO_BITSIZE(this->spec.format) / 8)) / this->spec.channels) / ((CFTimeInterval)this->spec.freq)) * 2.0;
+        const CFTimeInterval secs = (((this->spec.size / (SDL_AUDIO_BITSIZE(this->spec.format) / 8.0)) / this->spec.channels) / ((CFTimeInterval)this->spec.freq)) * 2.0;
         CFRunLoopRunInMode(kCFRunLoopDefaultMode, secs, 0);
     }
 
@@ -1084,13 +1092,15 @@ static int COREAUDIO_OpenDevice(_THIS, const char *devname)
     }
     this->spec.format = test_format;
     strdesc->mBitsPerChannel = SDL_AUDIO_BITSIZE(test_format);
-    if (SDL_AUDIO_ISBIGENDIAN(test_format))
+    if (SDL_AUDIO_ISBIGENDIAN(test_format)) {
         strdesc->mFormatFlags |= kLinearPCMFormatFlagIsBigEndian;
+    }
 
-    if (SDL_AUDIO_ISFLOAT(test_format))
+    if (SDL_AUDIO_ISFLOAT(test_format)) {
         strdesc->mFormatFlags |= kLinearPCMFormatFlagIsFloat;
-    else if (SDL_AUDIO_ISSIGNED(test_format))
+    } else if (SDL_AUDIO_ISSIGNED(test_format)) {
         strdesc->mFormatFlags |= kLinearPCMFormatFlagIsSignedInteger;
+    }
 
     strdesc->mBytesPerFrame = strdesc->mChannelsPerFrame * strdesc->mBitsPerChannel / 8;
     strdesc->mBytesPerPacket = strdesc->mBytesPerFrame * strdesc->mFramesPerPacket;
@@ -1230,12 +1240,14 @@ static int COREAUDIO_GetDefaultAudioInfo(char **name, SDL_AudioSpec *spec, int i
     spec->freq = (int)sampleRate;
 
     result = AudioObjectGetPropertyDataSize(devid, &bufaddr, 0, NULL, &size);
-    if (result != noErr)
+    if (result != noErr) {
         return SDL_SetError("%s: Default Device Data Size not found", "coreaudio");
+    }
 
     buflist = (AudioBufferList *)SDL_malloc(size);
-    if (buflist == NULL)
+    if (buflist == NULL) {
         return SDL_SetError("%s: Default Device Buffer List not found", "coreaudio");
+    }
 
     result = AudioObjectGetPropertyData(devid, &bufaddr, 0, NULL,
                                         &size, buflist);

+ 2 - 2
src/audio/dsp/SDL_dspaudio.c

@@ -199,8 +199,8 @@ static int DSP_OpenDevice(_THIS, const char *devname)
     SDL_CalculateAudioSpec(&this->spec);
 
     /* Determine the power of two of the fragment size */
-    for (frag_spec = 0; (0x01U << frag_spec) < this->spec.size; ++frag_spec)
-        ;
+    for (frag_spec = 0; (0x01U << frag_spec) < this->spec.size; ++frag_spec) {
+    }
     if ((0x01U << frag_spec) != this->spec.size) {
         return SDL_SetError("Fragment size must be a power of two");
     }

+ 11 - 3
src/audio/jack/SDL_jackaudio.c

@@ -162,7 +162,7 @@ static int jackProcessPlaybackCallback(jack_nframes_t nframes, void *arg)
     for (channelsi = 0; channelsi < total_channels; channelsi++) {
         float *dst = (float *)JACK_jack_port_get_buffer(ports[channelsi], nframes);
         if (dst) {
-            const float *src = ((float *)this->hidden->iobuffer) + channelsi;
+            const float *src = this->hidden->iobuffer + channelsi;
             int framesi;
             for (framesi = 0; framesi < total_frames; framesi++) {
                 *(dst++) = *src;
@@ -202,7 +202,7 @@ static int jackProcessCaptureCallback(jack_nframes_t nframes, void *arg)
         for (channelsi = 0; channelsi < total_channels; channelsi++) {
             const float *src = (const float *)JACK_jack_port_get_buffer(ports[channelsi], nframes);
             if (src) {
-                float *dst = ((float *)this->hidden->iobuffer) + channelsi;
+                float *dst = this->hidden->iobuffer + channelsi;
                 int framesi;
                 for (framesi = 0; framesi < total_frames; framesi++) {
                     *dst = *(src++);
@@ -312,6 +312,7 @@ static int JACK_OpenDevice(_THIS, const char *devname)
         }
     }
     if (channels == 0) {
+        SDL_free(audio_ports);
         return SDL_SetError("No physical JACK ports available");
     }
 
@@ -327,36 +328,42 @@ static int JACK_OpenDevice(_THIS, const char *devname)
 
     this->hidden->iosem = SDL_CreateSemaphore(0);
     if (!this->hidden->iosem) {
+        SDL_free(audio_ports);
         return -1; /* error was set by SDL_CreateSemaphore */
     }
 
     this->hidden->iobuffer = (float *)SDL_calloc(1, this->spec.size);
     if (!this->hidden->iobuffer) {
+        SDL_free(audio_ports);
         return SDL_OutOfMemory();
     }
 
     /* Build SDL's ports, which we will connect to the device ports. */
     this->hidden->sdlports = (jack_port_t **)SDL_calloc(channels, sizeof(jack_port_t *));
     if (this->hidden->sdlports == NULL) {
+        SDL_free(audio_ports);
         return SDL_OutOfMemory();
     }
 
     for (i = 0; i < channels; i++) {
         char portname[32];
-        SDL_snprintf(portname, sizeof(portname), "sdl_jack_%s_%d", sdlportstr, i);
+        (void)SDL_snprintf(portname, sizeof(portname), "sdl_jack_%s_%d", sdlportstr, i);
         this->hidden->sdlports[i] = JACK_jack_port_register(client, portname, JACK_DEFAULT_AUDIO_TYPE, sdlportflags, 0);
         if (this->hidden->sdlports[i] == NULL) {
+            SDL_free(audio_ports);
             return SDL_SetError("jack_port_register failed");
         }
     }
 
     if (JACK_jack_set_process_callback(client, callback, this) != 0) {
+        SDL_free(audio_ports);
         return SDL_SetError("JACK: Couldn't set process callback");
     }
 
     JACK_jack_on_shutdown(client, jackShutdownCallback, this);
 
     if (JACK_jack_activate(client) != 0) {
+        SDL_free(audio_ports);
         return SDL_SetError("Failed to activate JACK client");
     }
 
@@ -366,6 +373,7 @@ static int JACK_OpenDevice(_THIS, const char *devname)
         const char *srcport = iscapture ? devports[audio_ports[i]] : sdlport;
         const char *dstport = iscapture ? sdlport : devports[audio_ports[i]];
         if (JACK_jack_connect(client, srcport, dstport) != 0) {
+            SDL_free(audio_ports);
             return SDL_SetError("Couldn't connect JACK ports: %s => %s", srcport, dstport);
         }
     }

+ 12 - 11
src/audio/pipewire/SDL_pipewire.c

@@ -144,11 +144,8 @@ static int pipewire_dlsym(const char *fn, void **addr)
 
 static int load_pipewire_library()
 {
-    if ((pipewire_handle = SDL_LoadObject(pipewire_library))) {
-        return 0;
-    }
-
-    return -1;
+    pipewire_handle = SDL_LoadObject(pipewire_library);
+    return pipewire_handle != NULL ? 0 : -1;
 }
 
 static void unload_pipewire_library()
@@ -966,7 +963,8 @@ static void output_callback(void *data)
     }
 
     /* See if a buffer is available */
-    if ((pw_buf = PIPEWIRE_pw_stream_dequeue_buffer(stream)) == NULL) {
+    pw_buf = PIPEWIRE_pw_stream_dequeue_buffer(stream);
+    if (pw_buf == NULL) {
         return;
     }
 
@@ -1035,8 +1033,8 @@ static void input_callback(void *data)
     }
 
     spa_buf = pw_buf->buffer;
-
-    if ((src = (Uint8 *)spa_buf->datas[0].data) == NULL) {
+    (src = (Uint8 *)spa_buf->datas[0].data);
+    if (src == NULL) {
         return;
     }
 
@@ -1179,7 +1177,9 @@ static int PIPEWIRE_OpenDevice(_THIS, const char *devname)
         return SDL_SetError("Pipewire: Failed to set audio format parameters");
     }
 
-    if ((this->hidden = priv = SDL_calloc(1, sizeof(struct SDL_PrivateAudioData))) == NULL) {
+    priv = SDL_calloc(1, sizeof(struct SDL_PrivateAudioData));
+    this->hidden = priv;
+    if (priv == NULL) {
         return SDL_OutOfMemory();
     }
 
@@ -1191,7 +1191,7 @@ static int PIPEWIRE_OpenDevice(_THIS, const char *devname)
         this->spec.size = this->spec.samples * priv->stride;
     }
 
-    SDL_snprintf(thread_name, sizeof(thread_name), "SDLAudio%c%ld", (iscapture) ? 'C' : 'P', (long)this->handle);
+    (void)SDL_snprintf(thread_name, sizeof(thread_name), "SDLAudio%c%ld", (iscapture) ? 'C' : 'P', (long)this->handle);
     priv->loop = PIPEWIRE_pw_thread_loop_new(thread_name, NULL);
     if (priv->loop == NULL) {
         return SDL_SetError("Pipewire: Failed to create stream loop (%i)", errno);
@@ -1234,7 +1234,8 @@ static int PIPEWIRE_OpenDevice(_THIS, const char *devname)
             const struct io_node *node;
 
             PIPEWIRE_pw_thread_loop_lock(hotplug_loop);
-            if ((node = io_list_get_by_id(node_id))) {
+            node = io_list_get_by_id(node_id);
+            if (node != NULL) {
                 PIPEWIRE_pw_properties_set(props, PW_KEY_TARGET_OBJECT, node->path);
             }
             PIPEWIRE_pw_thread_loop_unlock(hotplug_loop);

+ 19 - 16
src/audio/sndio/SDL_sndioaudio.c

@@ -180,7 +180,8 @@ static int SNDIO_CaptureFromDevice(_THIS, void *buffer, int buflen)
     /* Emulate a blocking read */
     r = SNDIO_sio_read(this->hidden->dev, buffer, buflen);
     while (r == 0 && !SNDIO_sio_eof(this->hidden->dev)) {
-        if ((nfds = SNDIO_sio_pollfd(this->hidden->dev, this->hidden->pfd, POLLIN)) <= 0 || poll(this->hidden->pfd, nfds, INFTIM) < 0) {
+        nfds = SNDIO_sio_pollfd(this->hidden->dev, this->hidden->pfd, POLLIN);
+        if (nfds <= 0 || poll(this->hidden->pfd, nfds, INFTIM) < 0) {
             return -1;
         }
         revents = SNDIO_sio_revents(this->hidden->dev, this->hidden->pfd);
@@ -237,16 +238,18 @@ static int SNDIO_OpenDevice(_THIS, const char *devname)
     this->hidden->mixlen = this->spec.size;
 
     /* Capture devices must be non-blocking for SNDIO_FlushCapture */
-    if ((this->hidden->dev =
-             SNDIO_sio_open(devname != NULL ? devname : SIO_DEVANY,
-                            iscapture ? SIO_REC : SIO_PLAY, iscapture)) == NULL) {
+    this->hidden->dev = SNDIO_sio_open(devname != NULL ? devname : SIO_DEVANY,
+                                       iscapture ? SIO_REC : SIO_PLAY, iscapture);
+    if (this->hidden->dev == NULL) {
         return SDL_SetError("sio_open() failed");
     }
 
     /* Allocate the pollfd array for capture devices */
-    if (iscapture && (this->hidden->pfd =
-                          SDL_malloc(sizeof(struct pollfd) * SNDIO_sio_nfds(this->hidden->dev))) == NULL) {
-        return SDL_OutOfMemory();
+    if (iscapture) {
+        this->hidden->pfd = SDL_malloc(sizeof(struct pollfd) * SNDIO_sio_nfds(this->hidden->dev));
+        if (this->hidden->pfd == NULL) {
+            return SDL_OutOfMemory();
+        }
     }
 
     SNDIO_sio_initpar(&par);
@@ -282,23 +285,23 @@ static int SNDIO_OpenDevice(_THIS, const char *devname)
         return SDL_SetError("%s: Unsupported audio format", "sndio");
     }
 
-    if ((par.bps == 4) && (par.sig) && (par.le))
+    if ((par.bps == 4) && (par.sig) && (par.le)) {
         this->spec.format = AUDIO_S32LSB;
-    else if ((par.bps == 4) && (par.sig) && (!par.le))
+    } else if ((par.bps == 4) && (par.sig) && (!par.le)) {
         this->spec.format = AUDIO_S32MSB;
-    else if ((par.bps == 2) && (par.sig) && (par.le))
+    } else if ((par.bps == 2) && (par.sig) && (par.le)) {
         this->spec.format = AUDIO_S16LSB;
-    else if ((par.bps == 2) && (par.sig) && (!par.le))
+    } else if ((par.bps == 2) && (par.sig) && (!par.le)) {
         this->spec.format = AUDIO_S16MSB;
-    else if ((par.bps == 2) && (!par.sig) && (par.le))
+    } else if ((par.bps == 2) && (!par.sig) && (par.le)) {
         this->spec.format = AUDIO_U16LSB;
-    else if ((par.bps == 2) && (!par.sig) && (!par.le))
+    } else if ((par.bps == 2) && (!par.sig) && (!par.le)) {
         this->spec.format = AUDIO_U16MSB;
-    else if ((par.bps == 1) && (par.sig))
+    } else if ((par.bps == 1) && (par.sig)) {
         this->spec.format = AUDIO_S8;
-    else if ((par.bps == 1) && (!par.sig))
+    } else if ((par.bps == 1) && (!par.sig)) {
         this->spec.format = AUDIO_U8;
-    else {
+    } else {
         return SDL_SetError("sndio: Got unsupported hardware audio format.");
     }
 

+ 0 - 1
src/core/android/SDL_android.c

@@ -2480,7 +2480,6 @@ void Android_JNI_DestroyCustomCursor(int cursorID)
 {
     JNIEnv *env = Android_JNI_GetEnv();
     (*env)->CallStaticVoidMethod(env, mActivityClass, midDestroyCustomCursor, cursorID);
-    return;
 }
 
 SDL_bool Android_JNI_SetCustomCursor(int cursorID)

+ 6 - 6
src/core/linux/SDL_evdev.c

@@ -128,8 +128,7 @@ static int SDL_EVDEV_device_removed(const char *dev_path);
 
 static int SDL_EVDEV_device_added(const char *dev_path, int udev_class);
 #if SDL_USE_LIBUDEV
-static void SDL_EVDEV_udev_callback(SDL_UDEV_deviceevent udev_type, int udev_class,
-                                    const char *dev_path);
+static void SDL_EVDEV_udev_callback(SDL_UDEV_deviceevent udev_event, int udev_class, const char *dev_path);
 #endif /* SDL_USE_LIBUDEV */
 
 static Uint8 EVDEV_MouseButtons[] = {
@@ -319,10 +318,11 @@ void SDL_EVDEV_Poll(void)
                        next finger after earlist is released) */
                     if (item->is_touchscreen && events[i].code == BTN_TOUCH) {
                         if (item->touchscreen_data->max_slots == 1) {
-                            if (events[i].value)
+                            if (events[i].value) {
                                 item->touchscreen_data->slots[0].delta = EVDEV_TOUCH_SLOTDELTA_DOWN;
-                            else
+                            } else {
                                 item->touchscreen_data->slots[0].delta = EVDEV_TOUCH_SLOTDELTA_UP;
+                            }
                         }
                         break;
                     }
@@ -820,8 +820,8 @@ static int SDL_EVDEV_device_added(const char *dev_path, int udev_class)
     /* For now, we just treat a touchpad like a touchscreen */
     if (udev_class & (SDL_UDEV_DEVICE_TOUCHSCREEN | SDL_UDEV_DEVICE_TOUCHPAD)) {
         item->is_touchscreen = SDL_TRUE;
-
-        if ((ret = SDL_EVDEV_init_touchscreen(item, udev_class)) < 0) {
+        ret = SDL_EVDEV_init_touchscreen(item, udev_class);
+        if (ret < 0) {
             close(item->fd);
             SDL_free(item->path);
             SDL_free(item);

+ 4 - 4
src/core/linux/SDL_evdev_capabilities.c

@@ -37,10 +37,10 @@
 #endif
 
 extern int
-SDL_EVDEV_GuessDeviceClass(unsigned long bitmask_ev[NBITS(EV_MAX)],
-                           unsigned long bitmask_abs[NBITS(ABS_MAX)],
-                           unsigned long bitmask_key[NBITS(KEY_MAX)],
-                           unsigned long bitmask_rel[NBITS(REL_MAX)])
+SDL_EVDEV_GuessDeviceClass(const unsigned long bitmask_ev[NBITS(EV_MAX)],
+                           const unsigned long bitmask_abs[NBITS(ABS_MAX)],
+                           const unsigned long bitmask_key[NBITS(KEY_MAX)],
+                           const unsigned long bitmask_rel[NBITS(REL_MAX)])
 {
     struct range
     {

+ 4 - 4
src/core/linux/SDL_evdev_capabilities.h

@@ -47,10 +47,10 @@ typedef enum
 #define EVDEV_LONG(x)        ((x) / BITS_PER_LONG)
 #define test_bit(bit, array) ((array[EVDEV_LONG(bit)] >> EVDEV_OFF(bit)) & 1)
 
-extern int SDL_EVDEV_GuessDeviceClass(unsigned long bitmask_ev[NBITS(EV_MAX)],
-                                      unsigned long bitmask_abs[NBITS(ABS_MAX)],
-                                      unsigned long bitmask_key[NBITS(KEY_MAX)],
-                                      unsigned long bitmask_rel[NBITS(REL_MAX)]);
+extern int SDL_EVDEV_GuessDeviceClass(const unsigned long bitmask_ev[NBITS(EV_MAX)],
+                                      const unsigned long bitmask_abs[NBITS(ABS_MAX)],
+                                      const unsigned long bitmask_key[NBITS(KEY_MAX)],
+                                      const unsigned long bitmask_rel[NBITS(REL_MAX)]);
 
 #endif /* HAVE_LINUX_INPUT_H */
 

+ 53 - 45
src/core/linux/SDL_evdev_kbd.c

@@ -218,7 +218,7 @@ static void kbd_cleanup(void)
 
 static void SDL_EVDEV_kbd_reraise_signal(int sig)
 {
-    raise(sig);
+    (void)raise(sig);
 }
 
 siginfo_t *SDL_EVDEV_kdb_cleanup_siginfo = NULL;
@@ -303,7 +303,7 @@ static void kbd_register_emerg_cleanup(SDL_EVDEV_keyboard_state *kbd)
          * functions that are called when the shared library is unloaded.
          * -- man atexit(3)
          */
-        atexit(kbd_cleanup_atexit);
+        (void)atexit(kbd_cleanup_atexit);
         kbd_cleanup_atexit_installed = 1;
     }
 
@@ -407,33 +407,33 @@ SDL_EVDEV_kbd_init(void)
     return kbd;
 }
 
-void SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *kbd)
+void SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *state)
 {
-    if (kbd == NULL) {
+    if (state == NULL) {
         return;
     }
 
     kbd_unregister_emerg_cleanup();
 
-    if (kbd->console_fd >= 0) {
+    if (state->console_fd >= 0) {
         /* Restore the original keyboard mode */
-        ioctl(kbd->console_fd, KDSKBMODE, kbd->old_kbd_mode);
+        ioctl(state->console_fd, KDSKBMODE, state->old_kbd_mode);
 
-        close(kbd->console_fd);
-        kbd->console_fd = -1;
+        close(state->console_fd);
+        state->console_fd = -1;
     }
 
-    if (kbd->key_maps && kbd->key_maps != default_key_maps) {
+    if (state->key_maps && state->key_maps != default_key_maps) {
         int i;
         for (i = 0; i < MAX_NR_KEYMAPS; ++i) {
-            if (kbd->key_maps[i]) {
-                SDL_free(kbd->key_maps[i]);
+            if (state->key_maps[i]) {
+                SDL_free(state->key_maps[i]);
             }
         }
-        SDL_free(kbd->key_maps);
+        SDL_free(state->key_maps);
     }
 
-    SDL_free(kbd);
+    SDL_free(state);
 }
 
 /*
@@ -449,10 +449,9 @@ static void put_queue(SDL_EVDEV_keyboard_state *kbd, uint c)
 
 static void put_utf8(SDL_EVDEV_keyboard_state *kbd, uint c)
 {
-    if (c < 0x80)
-        /*  0******* */
-        put_queue(kbd, c);
-    else if (c < 0x800) {
+    if (c < 0x80) {
+        put_queue(kbd, c); /*  0******* */
+    } else if (c < 0x800) {
         /* 110***** 10****** */
         put_queue(kbd, 0xc0 | (c >> 6));
         put_queue(kbd, 0x80 | (c & 0x3f));
@@ -626,8 +625,9 @@ static void k_self(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_f
 
 static void k_deadunicode(SDL_EVDEV_keyboard_state *kbd, unsigned int value, char up_flag)
 {
-    if (up_flag)
+    if (up_flag) {
         return;
+    }
 
     kbd->diacr = (kbd->diacr ? handle_diacr(kbd, value) : value);
 }
@@ -660,8 +660,9 @@ static void k_pad(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_fl
 {
     static const char pad_chars[] = "0123456789+-*/\015,.?()#";
 
-    if (up_flag)
+    if (up_flag) {
         return; /* no action, if this is a key release */
+    }
 
     if (!vc_kbd_led(kbd, K_NUMLOCK)) {
         /* unprintable action */
@@ -675,8 +676,9 @@ static void k_shift(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_
 {
     int old_state = kbd->shift_state;
 
-    if (kbd->rep)
+    if (kbd->rep) {
         return;
+    }
     /*
      * Mimic typewriter:
      * a CapsShift key acts like Shift but undoes CapsLock
@@ -696,13 +698,15 @@ static void k_shift(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_
         if (kbd->shift_down[value]) {
             kbd->shift_down[value]--;
         }
-    } else
+    } else {
         kbd->shift_down[value]++;
+    }
 
-    if (kbd->shift_down[value])
+    if (kbd->shift_down[value]) {
         kbd->shift_state |= (1 << value);
-    else
+    } else {
         kbd->shift_state &= ~(1 << value);
+    }
 
     /* kludge */
     if (up_flag && kbd->shift_state != old_state && kbd->npadch != -1) {
@@ -719,8 +723,9 @@ static void k_ascii(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_
 {
     int base;
 
-    if (up_flag)
+    if (up_flag) {
         return;
+    }
 
     if (value < 10) {
         /* decimal input of code, while Alt depressed */
@@ -731,16 +736,18 @@ static void k_ascii(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_
         base = 16;
     }
 
-    if (kbd->npadch == -1)
+    if (kbd->npadch == -1) {
         kbd->npadch = value;
-    else
+    } else {
         kbd->npadch = kbd->npadch * base + value;
+    }
 }
 
 static void k_lock(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag)
 {
-    if (up_flag || kbd->rep)
+    if (up_flag || kbd->rep) {
         return;
+    }
 
     chg_vc_kbd_lock(kbd, value);
 }
@@ -748,8 +755,9 @@ static void k_lock(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_f
 static void k_slock(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag)
 {
     k_shift(kbd, value, up_flag);
-    if (up_flag || kbd->rep)
+    if (up_flag || kbd->rep) {
         return;
+    }
 
     chg_vc_kbd_slock(kbd, value);
     /* try to make Alt, oops, AltGr and such work */
@@ -763,26 +771,26 @@ static void k_brl(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_fl
 {
 }
 
-void SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int down)
+void SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *state, unsigned int keycode, int down)
 {
     unsigned char shift_final;
     unsigned char type;
     unsigned short *key_map;
     unsigned short keysym;
 
-    if (kbd == NULL) {
+    if (state == NULL) {
         return;
     }
 
-    kbd->rep = (down == 2);
+    state->rep = (down == 2);
 
-    shift_final = (kbd->shift_state | kbd->slockstate) ^ kbd->lockstate;
-    key_map = kbd->key_maps[shift_final];
+    shift_final = (state->shift_state | state->slockstate) ^ state->lockstate;
+    key_map = state->key_maps[shift_final];
     if (key_map == NULL) {
         /* Unsupported shift state (e.g. ctrl = 4, alt = 8), just reset to the default state */
-        kbd->shift_state = 0;
-        kbd->slockstate = 0;
-        kbd->lockstate = 0;
+        state->shift_state = 0;
+        state->slockstate = 0;
+        state->lockstate = 0;
         return;
     }
 
@@ -796,7 +804,7 @@ void SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode,
 
     if (type < 0xf0) {
         if (down) {
-            put_utf8(kbd, keysym);
+            put_utf8(state, keysym);
         }
     } else {
         type -= 0xf0;
@@ -805,25 +813,25 @@ void SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode,
         if (type == KT_LETTER) {
             type = KT_LATIN;
 
-            if (vc_kbd_led(kbd, K_CAPSLOCK)) {
-                key_map = kbd->key_maps[shift_final ^ (1 << KG_SHIFT)];
+            if (vc_kbd_led(state, K_CAPSLOCK)) {
+                key_map = state->key_maps[shift_final ^ (1 << KG_SHIFT)];
                 if (key_map) {
                     keysym = key_map[keycode];
                 }
             }
         }
 
-        (*k_handler[type])(kbd, keysym & 0xff, !down);
+        (*k_handler[type])(state, keysym & 0xff, !down);
 
         if (type != KT_SLOCK) {
-            kbd->slockstate = 0;
+            state->slockstate = 0;
         }
     }
 
-    if (kbd->text_len > 0) {
-        kbd->text[kbd->text_len] = '\0';
-        SDL_SendKeyboardText(kbd->text);
-        kbd->text_len = 0;
+    if (state->text_len > 0) {
+        state->text[state->text_len] = '\0';
+        SDL_SendKeyboardText(state->text);
+        state->text_len = 0;
     }
 }
 

+ 2 - 2
src/core/linux/SDL_fcitx.c

@@ -64,9 +64,9 @@ static char *GetAppName()
     int linksize;
 
 #if defined(__LINUX__)
-    SDL_snprintf(procfile, sizeof(procfile), "/proc/%d/exe", getpid());
+    (void)SDL_snprintf(procfile, sizeof procfile, "/proc/%d/exe", getpid());
 #elif defined(__FREEBSD__)
-    SDL_snprintf(procfile, sizeof(procfile), "/proc/%d/file", getpid());
+    (void)SDL_snprintf(procfile, sizeof procfile, "/proc/%d/file", getpid());
 #endif
     linksize = readlink(procfile, linkfile, sizeof(linkfile) - 1);
     if (linksize > 0) {

+ 5 - 5
src/core/linux/SDL_ibus.c

@@ -324,7 +324,7 @@ static char *IBus_ReadAddressFromFile(const char *file_path)
         }
     }
 
-    fclose(addr_file);
+    (void)fclose(addr_file);
 
     if (success) {
         return SDL_strdup(addr_buf + (sizeof("IBUS_ADDRESS=") - 1));
@@ -407,14 +407,14 @@ static char *IBus_GetDBusAddressFilename(void)
             SDL_free(display);
             return NULL;
         }
-        SDL_snprintf(config_dir, sizeof(config_dir), "%s/.config", home_env);
+        (void)SDL_snprintf(config_dir, sizeof config_dir, "%s/.config", home_env);
     }
 
     key = dbus->get_local_machine_id();
 
     SDL_memset(file_path, 0, sizeof(file_path));
-    SDL_snprintf(file_path, sizeof(file_path), "%s/ibus/bus/%s-%s-%s",
-                 config_dir, key, host, disp_num);
+    (void)SDL_snprintf(file_path, sizeof file_path, "%s/ibus/bus/%s-%s-%s",
+                       config_dir, key, host, disp_num);
     dbus->free(key);
     SDL_free(display);
 
@@ -488,7 +488,7 @@ static SDL_bool IBus_SetupConnection(SDL_DBusContext *dbus, const char *addr)
 
     if (result) {
         char matchstr[128];
-        SDL_snprintf(matchstr, sizeof(matchstr), "type='signal',interface='%s'", ibus_input_interface);
+        (void)SDL_snprintf(matchstr, sizeof matchstr, "type='signal',interface='%s'", ibus_input_interface);
         SDL_free(input_ctx_path);
         input_ctx_path = SDL_strdup(path);
         SDL_AddHintCallback(SDL_HINT_IME_INTERNAL_EDITING, IBus_SetCapabilities, NULL);

+ 4 - 4
src/core/windows/SDL_windows.c

@@ -268,10 +268,10 @@ WIN_LookupAudioDeviceName(const WCHAR *name, const GUID *guid)
     }
 
     ptr = (const unsigned char *)guid;
-    SDL_snprintf(keystr, sizeof(keystr),
-                 "System\\CurrentControlSet\\Control\\MediaCategories\\{%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
-                 ptr[3], ptr[2], ptr[1], ptr[0], ptr[5], ptr[4], ptr[7], ptr[6],
-                 ptr[8], ptr[9], ptr[10], ptr[11], ptr[12], ptr[13], ptr[14], ptr[15]);
+    (void)SDL_snprintf(keystr, sizeof keystr,
+                       "System\\CurrentControlSet\\Control\\MediaCategories\\{%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
+                       ptr[3], ptr[2], ptr[1], ptr[0], ptr[5], ptr[4], ptr[7], ptr[6],
+                       ptr[8], ptr[9], ptr[10], ptr[11], ptr[12], ptr[13], ptr[14], ptr[15]);
 
     strw = WIN_UTF8ToString(keystr);
     rc = (RegOpenKeyExW(HKEY_LOCAL_MACHINE, strw, 0, KEY_QUERY_VALUE, &hkey) == ERROR_SUCCESS);

+ 90 - 90
src/events/SDL_events.c

@@ -179,7 +179,7 @@ static void SDL_LogEvent(const SDL_Event *event)
         return;
     }
 
-/* this is to make SDL_snprintf() calls cleaner. */
+/* this is to make (void)SDL_snprintf() calls cleaner. */
 #define uint unsigned int
 
     name[0] = '\0';
@@ -191,13 +191,13 @@ static void SDL_LogEvent(const SDL_Event *event)
         char plusstr[16];
         SDL_strlcpy(name, "SDL_USEREVENT", sizeof(name));
         if (event->type > SDL_USEREVENT) {
-            SDL_snprintf(plusstr, sizeof(plusstr), "+%u", ((uint)event->type) - SDL_USEREVENT);
+            (void)SDL_snprintf(plusstr, sizeof(plusstr), "+%u", ((uint)event->type) - SDL_USEREVENT);
         } else {
             plusstr[0] = '\0';
         }
-        SDL_snprintf(details, sizeof(details), "%s (timestamp=%u windowid=%u code=%d data1=%p data2=%p)",
-                     plusstr, (uint)event->user.timestamp, (uint)event->user.windowID,
-                     (int)event->user.code, event->user.data1, event->user.data2);
+        (void)SDL_snprintf(details, sizeof(details), "%s (timestamp=%u windowid=%u code=%d data1=%p data2=%p)",
+                           plusstr, (uint)event->user.timestamp, (uint)event->user.windowID,
+                           (int)event->user.code, event->user.data1, event->user.data2);
     }
 
     switch (event->type) {
@@ -208,7 +208,7 @@ static void SDL_LogEvent(const SDL_Event *event)
         SDL_strlcpy(details, " (THIS IS PROBABLY A BUG!)", sizeof(details));
         break;
         SDL_EVENT_CASE(SDL_QUIT)
-        SDL_snprintf(details, sizeof(details), " (timestamp=%u)", (uint)event->quit.timestamp);
+        (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u)", (uint)event->quit.timestamp);
         break;
         SDL_EVENT_CASE(SDL_APP_TERMINATING)
         break;
@@ -252,8 +252,8 @@ static void SDL_LogEvent(const SDL_Event *event)
                 SDL_strlcpy(name2, "UNKNOWN (bug? fixme?)", sizeof(name2));
                 break;
             }
-            SDL_snprintf(details, sizeof(details), " (timestamp=%u display=%u event=%s data1=%d)",
-                         (uint)event->display.timestamp, (uint)event->display.display, name2, (int)event->display.data1);
+            (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u display=%u event=%s data1=%d)",
+                               (uint)event->display.timestamp, (uint)event->display.display, name2, (int)event->display.data1);
             break;
         }
 
@@ -291,24 +291,24 @@ static void SDL_LogEvent(const SDL_Event *event)
                 SDL_strlcpy(name2, "UNKNOWN (bug? fixme?)", sizeof(name2));
                 break;
             }
-            SDL_snprintf(details, sizeof(details), " (timestamp=%u windowid=%u event=%s data1=%d data2=%d)",
-                         (uint)event->window.timestamp, (uint)event->window.windowID, name2, (int)event->window.data1, (int)event->window.data2);
+            (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u windowid=%u event=%s data1=%d data2=%d)",
+                               (uint)event->window.timestamp, (uint)event->window.windowID, name2, (int)event->window.data1, (int)event->window.data2);
             break;
         }
 
         SDL_EVENT_CASE(SDL_SYSWMEVENT)
         /* !!! FIXME: we don't delve further at the moment. */
-        SDL_snprintf(details, sizeof(details), " (timestamp=%u)", (uint)event->syswm.timestamp);
+        (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u)", (uint)event->syswm.timestamp);
         break;
 
-#define PRINT_KEY_EVENT(event)                                                                                             \
-    SDL_snprintf(details, sizeof(details), " (timestamp=%u windowid=%u state=%s repeat=%s scancode=%u keycode=%u mod=%u)", \
-                 (uint)event->key.timestamp, (uint)event->key.windowID,                                                    \
-                 event->key.state == SDL_PRESSED ? "pressed" : "released",                                                 \
-                 event->key.repeat ? "true" : "false",                                                                     \
-                 (uint)event->key.keysym.scancode,                                                                         \
-                 (uint)event->key.keysym.sym,                                                                              \
-                 (uint)event->key.keysym.mod)
+#define PRINT_KEY_EVENT(event)                                                                                                   \
+    (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u windowid=%u state=%s repeat=%s scancode=%u keycode=%u mod=%u)", \
+                       (uint)event->key.timestamp, (uint)event->key.windowID,                                                    \
+                       event->key.state == SDL_PRESSED ? "pressed" : "released",                                                 \
+                       event->key.repeat ? "true" : "false",                                                                     \
+                       (uint)event->key.keysym.scancode,                                                                         \
+                       (uint)event->key.keysym.sym,                                                                              \
+                       (uint)event->key.keysym.mod)
         SDL_EVENT_CASE(SDL_KEYDOWN)
         PRINT_KEY_EVENT(event);
         break;
@@ -318,29 +318,29 @@ static void SDL_LogEvent(const SDL_Event *event)
 #undef PRINT_KEY_EVENT
 
         SDL_EVENT_CASE(SDL_TEXTEDITING)
-        SDL_snprintf(details, sizeof(details), " (timestamp=%u windowid=%u text='%s' start=%d length=%d)",
-                     (uint)event->edit.timestamp, (uint)event->edit.windowID,
-                     event->edit.text, (int)event->edit.start, (int)event->edit.length);
+        (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u windowid=%u text='%s' start=%d length=%d)",
+                           (uint)event->edit.timestamp, (uint)event->edit.windowID,
+                           event->edit.text, (int)event->edit.start, (int)event->edit.length);
         break;
 
         SDL_EVENT_CASE(SDL_TEXTINPUT)
-        SDL_snprintf(details, sizeof(details), " (timestamp=%u windowid=%u text='%s')", (uint)event->text.timestamp, (uint)event->text.windowID, event->text.text);
+        (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u windowid=%u text='%s')", (uint)event->text.timestamp, (uint)event->text.windowID, event->text.text);
         break;
 
         SDL_EVENT_CASE(SDL_MOUSEMOTION)
-        SDL_snprintf(details, sizeof(details), " (timestamp=%u windowid=%u which=%u state=%u x=%d y=%d xrel=%d yrel=%d)",
-                     (uint)event->motion.timestamp, (uint)event->motion.windowID,
-                     (uint)event->motion.which, (uint)event->motion.state,
-                     (int)event->motion.x, (int)event->motion.y,
-                     (int)event->motion.xrel, (int)event->motion.yrel);
+        (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u windowid=%u which=%u state=%u x=%d y=%d xrel=%d yrel=%d)",
+                           (uint)event->motion.timestamp, (uint)event->motion.windowID,
+                           (uint)event->motion.which, (uint)event->motion.state,
+                           (int)event->motion.x, (int)event->motion.y,
+                           (int)event->motion.xrel, (int)event->motion.yrel);
         break;
 
-#define PRINT_MBUTTON_EVENT(event)                                                                                        \
-    SDL_snprintf(details, sizeof(details), " (timestamp=%u windowid=%u which=%u button=%u state=%s clicks=%u x=%d y=%d)", \
-                 (uint)event->button.timestamp, (uint)event->button.windowID,                                             \
-                 (uint)event->button.which, (uint)event->button.button,                                                   \
-                 event->button.state == SDL_PRESSED ? "pressed" : "released",                                             \
-                 (uint)event->button.clicks, (int)event->button.x, (int)event->button.y)
+#define PRINT_MBUTTON_EVENT(event)                                                                                              \
+    (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u windowid=%u which=%u button=%u state=%s clicks=%u x=%d y=%d)", \
+                       (uint)event->button.timestamp, (uint)event->button.windowID,                                             \
+                       (uint)event->button.which, (uint)event->button.button,                                                   \
+                       event->button.state == SDL_PRESSED ? "pressed" : "released",                                             \
+                       (uint)event->button.clicks, (int)event->button.x, (int)event->button.y)
         SDL_EVENT_CASE(SDL_MOUSEBUTTONDOWN)
         PRINT_MBUTTON_EVENT(event);
         break;
@@ -350,35 +350,35 @@ static void SDL_LogEvent(const SDL_Event *event)
 #undef PRINT_MBUTTON_EVENT
 
         SDL_EVENT_CASE(SDL_MOUSEWHEEL)
-        SDL_snprintf(details, sizeof(details), " (timestamp=%u windowid=%u which=%u x=%d y=%d preciseX=%f preciseY=%f direction=%s)",
-                     (uint)event->wheel.timestamp, (uint)event->wheel.windowID,
-                     (uint)event->wheel.which, (int)event->wheel.x, (int)event->wheel.y,
-                     event->wheel.preciseX, event->wheel.preciseY,
-                     event->wheel.direction == SDL_MOUSEWHEEL_NORMAL ? "normal" : "flipped");
+        (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u windowid=%u which=%u x=%d y=%d preciseX=%f preciseY=%f direction=%s)",
+                           (uint)event->wheel.timestamp, (uint)event->wheel.windowID,
+                           (uint)event->wheel.which, (int)event->wheel.x, (int)event->wheel.y,
+                           event->wheel.preciseX, event->wheel.preciseY,
+                           event->wheel.direction == SDL_MOUSEWHEEL_NORMAL ? "normal" : "flipped");
         break;
 
         SDL_EVENT_CASE(SDL_JOYAXISMOTION)
-        SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%d axis=%u value=%d)",
-                     (uint)event->jaxis.timestamp, (int)event->jaxis.which,
-                     (uint)event->jaxis.axis, (int)event->jaxis.value);
+        (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%d axis=%u value=%d)",
+                           (uint)event->jaxis.timestamp, (int)event->jaxis.which,
+                           (uint)event->jaxis.axis, (int)event->jaxis.value);
         break;
 
         SDL_EVENT_CASE(SDL_JOYBALLMOTION)
-        SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%d ball=%u xrel=%d yrel=%d)",
-                     (uint)event->jball.timestamp, (int)event->jball.which,
-                     (uint)event->jball.ball, (int)event->jball.xrel, (int)event->jball.yrel);
+        (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%d ball=%u xrel=%d yrel=%d)",
+                           (uint)event->jball.timestamp, (int)event->jball.which,
+                           (uint)event->jball.ball, (int)event->jball.xrel, (int)event->jball.yrel);
         break;
 
         SDL_EVENT_CASE(SDL_JOYHATMOTION)
-        SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%d hat=%u value=%u)",
-                     (uint)event->jhat.timestamp, (int)event->jhat.which,
-                     (uint)event->jhat.hat, (uint)event->jhat.value);
+        (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%d hat=%u value=%u)",
+                           (uint)event->jhat.timestamp, (int)event->jhat.which,
+                           (uint)event->jhat.hat, (uint)event->jhat.value);
         break;
 
-#define PRINT_JBUTTON_EVENT(event)                                                        \
-    SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%d button=%u state=%s)", \
-                 (uint)event->jbutton.timestamp, (int)event->jbutton.which,               \
-                 (uint)event->jbutton.button, event->jbutton.state == SDL_PRESSED ? "pressed" : "released")
+#define PRINT_JBUTTON_EVENT(event)                                                              \
+    (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%d button=%u state=%s)", \
+                       (uint)event->jbutton.timestamp, (int)event->jbutton.which,               \
+                       (uint)event->jbutton.button, event->jbutton.state == SDL_PRESSED ? "pressed" : "released")
         SDL_EVENT_CASE(SDL_JOYBUTTONDOWN)
         PRINT_JBUTTON_EVENT(event);
         break;
@@ -387,7 +387,7 @@ static void SDL_LogEvent(const SDL_Event *event)
         break;
 #undef PRINT_JBUTTON_EVENT
 
-#define PRINT_JOYDEV_EVENT(event) SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%d)", (uint)event->jdevice.timestamp, (int)event->jdevice.which)
+#define PRINT_JOYDEV_EVENT(event) (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%d)", (uint)event->jdevice.timestamp, (int)event->jdevice.which)
         SDL_EVENT_CASE(SDL_JOYDEVICEADDED)
         PRINT_JOYDEV_EVENT(event);
         break;
@@ -397,15 +397,15 @@ static void SDL_LogEvent(const SDL_Event *event)
 #undef PRINT_JOYDEV_EVENT
 
         SDL_EVENT_CASE(SDL_CONTROLLERAXISMOTION)
-        SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%d axis=%u value=%d)",
-                     (uint)event->caxis.timestamp, (int)event->caxis.which,
-                     (uint)event->caxis.axis, (int)event->caxis.value);
+        (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%d axis=%u value=%d)",
+                           (uint)event->caxis.timestamp, (int)event->caxis.which,
+                           (uint)event->caxis.axis, (int)event->caxis.value);
         break;
 
-#define PRINT_CBUTTON_EVENT(event)                                                        \
-    SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%d button=%u state=%s)", \
-                 (uint)event->cbutton.timestamp, (int)event->cbutton.which,               \
-                 (uint)event->cbutton.button, event->cbutton.state == SDL_PRESSED ? "pressed" : "released")
+#define PRINT_CBUTTON_EVENT(event)                                                              \
+    (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%d button=%u state=%s)", \
+                       (uint)event->cbutton.timestamp, (int)event->cbutton.which,               \
+                       (uint)event->cbutton.button, event->cbutton.state == SDL_PRESSED ? "pressed" : "released")
         SDL_EVENT_CASE(SDL_CONTROLLERBUTTONDOWN)
         PRINT_CBUTTON_EVENT(event);
         break;
@@ -414,7 +414,7 @@ static void SDL_LogEvent(const SDL_Event *event)
         break;
 #undef PRINT_CBUTTON_EVENT
 
-#define PRINT_CONTROLLERDEV_EVENT(event) SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%d)", (uint)event->cdevice.timestamp, (int)event->cdevice.which)
+#define PRINT_CONTROLLERDEV_EVENT(event) (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%d)", (uint)event->cdevice.timestamp, (int)event->cdevice.which)
         SDL_EVENT_CASE(SDL_CONTROLLERDEVICEADDED)
         PRINT_CONTROLLERDEV_EVENT(event);
         break;
@@ -426,11 +426,11 @@ static void SDL_LogEvent(const SDL_Event *event)
         break;
 #undef PRINT_CONTROLLERDEV_EVENT
 
-#define PRINT_CTOUCHPAD_EVENT(event)                                                                               \
-    SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%d touchpad=%d finger=%d x=%f y=%f pressure=%f)", \
-                 (uint)event->ctouchpad.timestamp, (int)event->ctouchpad.which,                                    \
-                 (int)event->ctouchpad.touchpad, (int)event->ctouchpad.finger,                                     \
-                 event->ctouchpad.x, event->ctouchpad.y, event->ctouchpad.pressure)
+#define PRINT_CTOUCHPAD_EVENT(event)                                                                                     \
+    (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%d touchpad=%d finger=%d x=%f y=%f pressure=%f)", \
+                       (uint)event->ctouchpad.timestamp, (int)event->ctouchpad.which,                                    \
+                       (int)event->ctouchpad.touchpad, (int)event->ctouchpad.finger,                                     \
+                       event->ctouchpad.x, event->ctouchpad.y, event->ctouchpad.pressure)
         SDL_EVENT_CASE(SDL_CONTROLLERTOUCHPADDOWN)
         PRINT_CTOUCHPAD_EVENT(event);
         break;
@@ -443,16 +443,16 @@ static void SDL_LogEvent(const SDL_Event *event)
 #undef PRINT_CTOUCHPAD_EVENT
 
         SDL_EVENT_CASE(SDL_CONTROLLERSENSORUPDATE)
-        SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%d sensor=%d data[0]=%f data[1]=%f data[2]=%f)",
-                     (uint)event->csensor.timestamp, (int)event->csensor.which, (int)event->csensor.sensor,
-                     event->csensor.data[0], event->csensor.data[1], event->csensor.data[2]);
+        (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%d sensor=%d data[0]=%f data[1]=%f data[2]=%f)",
+                           (uint)event->csensor.timestamp, (int)event->csensor.which, (int)event->csensor.sensor,
+                           event->csensor.data[0], event->csensor.data[1], event->csensor.data[2]);
         break;
 
-#define PRINT_FINGER_EVENT(event)                                                                                                                \
-    SDL_snprintf(details, sizeof(details), " (timestamp=%u touchid=%" SDL_PRIs64 " fingerid=%" SDL_PRIs64 " x=%f y=%f dx=%f dy=%f pressure=%f)", \
-                 (uint)event->tfinger.timestamp, (long long)event->tfinger.touchId,                                                              \
-                 (long long)event->tfinger.fingerId, event->tfinger.x, event->tfinger.y,                                                         \
-                 event->tfinger.dx, event->tfinger.dy, event->tfinger.pressure)
+#define PRINT_FINGER_EVENT(event)                                                                                                                      \
+    (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u touchid=%" SDL_PRIs64 " fingerid=%" SDL_PRIs64 " x=%f y=%f dx=%f dy=%f pressure=%f)", \
+                       (uint)event->tfinger.timestamp, (long long)event->tfinger.touchId,                                                              \
+                       (long long)event->tfinger.fingerId, event->tfinger.x, event->tfinger.y,                                                         \
+                       event->tfinger.dx, event->tfinger.dy, event->tfinger.pressure)
         SDL_EVENT_CASE(SDL_FINGERDOWN)
         PRINT_FINGER_EVENT(event);
         break;
@@ -464,11 +464,11 @@ static void SDL_LogEvent(const SDL_Event *event)
         break;
 #undef PRINT_FINGER_EVENT
 
-#define PRINT_DOLLAR_EVENT(event)                                                                                                                \
-    SDL_snprintf(details, sizeof(details), " (timestamp=%u touchid=%" SDL_PRIs64 " gestureid=%" SDL_PRIs64 " numfingers=%u error=%f x=%f y=%f)", \
-                 (uint)event->dgesture.timestamp, (long long)event->dgesture.touchId,                                                            \
-                 (long long)event->dgesture.gestureId, (uint)event->dgesture.numFingers,                                                         \
-                 event->dgesture.error, event->dgesture.x, event->dgesture.y)
+#define PRINT_DOLLAR_EVENT(event)                                                                                                                      \
+    (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u touchid=%" SDL_PRIs64 " gestureid=%" SDL_PRIs64 " numfingers=%u error=%f x=%f y=%f)", \
+                       (uint)event->dgesture.timestamp, (long long)event->dgesture.touchId,                                                            \
+                       (long long)event->dgesture.gestureId, (uint)event->dgesture.numFingers,                                                         \
+                       event->dgesture.error, event->dgesture.x, event->dgesture.y)
         SDL_EVENT_CASE(SDL_DOLLARGESTURE)
         PRINT_DOLLAR_EVENT(event);
         break;
@@ -478,13 +478,13 @@ static void SDL_LogEvent(const SDL_Event *event)
 #undef PRINT_DOLLAR_EVENT
 
         SDL_EVENT_CASE(SDL_MULTIGESTURE)
-        SDL_snprintf(details, sizeof(details), " (timestamp=%u touchid=%" SDL_PRIs64 " dtheta=%f ddist=%f x=%f y=%f numfingers=%u)",
-                     (uint)event->mgesture.timestamp, (long long)event->mgesture.touchId,
-                     event->mgesture.dTheta, event->mgesture.dDist,
-                     event->mgesture.x, event->mgesture.y, (uint)event->mgesture.numFingers);
+        (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u touchid=%" SDL_PRIs64 " dtheta=%f ddist=%f x=%f y=%f numfingers=%u)",
+                           (uint)event->mgesture.timestamp, (long long)event->mgesture.touchId,
+                           event->mgesture.dTheta, event->mgesture.dDist,
+                           event->mgesture.x, event->mgesture.y, (uint)event->mgesture.numFingers);
         break;
 
-#define PRINT_DROP_EVENT(event) SDL_snprintf(details, sizeof(details), " (file='%s' timestamp=%u windowid=%u)", event->drop.file, (uint)event->drop.timestamp, (uint)event->drop.windowID)
+#define PRINT_DROP_EVENT(event) (void)SDL_snprintf(details, sizeof(details), " (file='%s' timestamp=%u windowid=%u)", event->drop.file, (uint)event->drop.timestamp, (uint)event->drop.windowID)
         SDL_EVENT_CASE(SDL_DROPFILE)
         PRINT_DROP_EVENT(event);
         break;
@@ -499,7 +499,7 @@ static void SDL_LogEvent(const SDL_Event *event)
         break;
 #undef PRINT_DROP_EVENT
 
-#define PRINT_AUDIODEV_EVENT(event) SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%u iscapture=%s)", (uint)event->adevice.timestamp, (uint)event->adevice.which, event->adevice.iscapture ? "true" : "false")
+#define PRINT_AUDIODEV_EVENT(event) (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%u iscapture=%s)", (uint)event->adevice.timestamp, (uint)event->adevice.which, event->adevice.iscapture ? "true" : "false")
         SDL_EVENT_CASE(SDL_AUDIODEVICEADDED)
         PRINT_AUDIODEV_EVENT(event);
         break;
@@ -509,10 +509,10 @@ static void SDL_LogEvent(const SDL_Event *event)
 #undef PRINT_AUDIODEV_EVENT
 
         SDL_EVENT_CASE(SDL_SENSORUPDATE)
-        SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%d data[0]=%f data[1]=%f data[2]=%f data[3]=%f data[4]=%f data[5]=%f)",
-                     (uint)event->sensor.timestamp, (int)event->sensor.which,
-                     event->sensor.data[0], event->sensor.data[1], event->sensor.data[2],
-                     event->sensor.data[3], event->sensor.data[4], event->sensor.data[5]);
+        (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%d data[0]=%f data[1]=%f data[2]=%f data[3]=%f data[4]=%f data[5]=%f)",
+                           (uint)event->sensor.timestamp, (int)event->sensor.which,
+                           event->sensor.data[0], event->sensor.data[1], event->sensor.data[2],
+                           event->sensor.data[3], event->sensor.data[4], event->sensor.data[5]);
         break;
 
 #undef SDL_EVENT_CASE
@@ -524,7 +524,7 @@ static void SDL_LogEvent(const SDL_Event *event)
     default:
         if (!name[0]) {
             SDL_strlcpy(name, "UNKNOWN", sizeof(name));
-            SDL_snprintf(details, sizeof(details), " #%u! (Bug? FIXME?)", (uint)event->type);
+            (void)SDL_snprintf(details, sizeof(details), " #%u! (Bug? FIXME?)", (uint)event->type);
         }
         break;
     }

+ 4 - 3
src/events/SDL_keyboard.c

@@ -1154,10 +1154,11 @@ SDL_GetScancodeName(SDL_Scancode scancode)
     }
 
     name = SDL_scancode_names[scancode];
-    if (name)
+    if (name != NULL) {
         return name;
-    else
-        return "";
+    }
+
+    return "";
 }
 
 SDL_Scancode SDL_GetScancodeFromName(const char *name)

+ 1 - 1
src/events/SDL_keyboard_c.h

@@ -70,7 +70,7 @@ extern SDL_bool SDL_HardwareKeyboardKeyPressed(void);
 extern int SDL_SendKeyboardText(const char *text);
 
 /* Send editing text for selected range from start to end */
-extern int SDL_SendEditingText(const char *text, int start, int end);
+extern int SDL_SendEditingText(const char *text, int start, int length);
 
 /* Shutdown the keyboard subsystem */
 extern void SDL_KeyboardQuit(void);

+ 1 - 1
src/events/SDL_mouse.c

@@ -381,7 +381,7 @@ static int GetScaledMouseDelta(float scale, int value, float *accum)
     return value;
 }
 
-static float CalculateSystemScale(SDL_Mouse *mouse, int *x, int *y)
+static float CalculateSystemScale(SDL_Mouse *mouse, const int *x, const int *y)
 {
     int i;
     int n = mouse->num_system_scale_values;

+ 1 - 1
src/events/SDL_quit.c

@@ -50,7 +50,7 @@ static SDL_bool send_foregrounding_pending = SDL_FALSE;
 static void SDL_HandleSIG(int sig)
 {
     /* Reset the signal handler */
-    signal(sig, SDL_HandleSIG);
+    (void)signal(sig, SDL_HandleSIG);
 
     /* Send a quit event next time the event loop pumps. */
     /* We can't send it in signal handler; SDL_malloc() might be interrupted! */

+ 1 - 1
src/file/SDL_rwops.c

@@ -722,7 +722,7 @@ void SDL_FreeRW(SDL_RWops *area)
 void *
 SDL_LoadFile_RW(SDL_RWops *src, size_t *datasize, int freesrc)
 {
-    const int FILE_CHUNK_SIZE = 1024;
+    static const Sint64 FILE_CHUNK_SIZE = 1024;
     Sint64 size;
     size_t size_read, size_total;
     void *data = NULL, *newdata;

+ 1 - 1
src/file/cocoa/SDL_rwopsbundlesupport.m

@@ -42,7 +42,7 @@ FILE *SDL_OpenFPFromBundleOrFallback(const char *file, const char *mode)
         NSString *full_path_with_file_to_try;
 
         /* If the file mode is writable, skip all the bundle stuff because generally the bundle is read-only. */
-        if (strcmp("r", mode) && strcmp("rb", mode)) {
+        if (SDL_strchr(mode, 'r') == NULL) {
             return fopen(file, mode);
         }
 

+ 2 - 2
src/filesystem/unix/SDL_sysfilesystem.c

@@ -321,9 +321,9 @@ SDL_GetPrefPath(const char *org, const char *app)
     }
 
     if (*org) {
-        SDL_snprintf(retval, len, "%s%s%s/%s/", envr, append, org, app);
+        (void)SDL_snprintf(retval, len, "%s%s%s/%s/", envr, append, org, app);
     } else {
-        SDL_snprintf(retval, len, "%s%s%s/", envr, append, app);
+        (void)SDL_snprintf(retval, len, "%s%s%s/", envr, append, app);
     }
 
     for (ptr = retval + 1; *ptr; ptr++) {

+ 5 - 4
src/haptic/SDL_haptic.c

@@ -240,12 +240,13 @@ int SDL_JoystickIsHaptic(SDL_Joystick *joystick)
 
     ret = SDL_SYS_JoystickIsHaptic(joystick);
 
-    if (ret > 0)
+    if (ret > 0) {
         return SDL_TRUE;
-    else if (ret == 0)
+    } else if (ret == 0) {
         return SDL_FALSE;
-    else
-        return -1;
+    }
+
+    return -1;
 }
 
 /*

+ 1 - 4
src/haptic/android/SDL_syshaptic.c

@@ -167,7 +167,6 @@ void SDL_SYS_HapticClose(SDL_Haptic *haptic)
 {
     ((SDL_hapticlist_item *)haptic->hwdata)->haptic = NULL;
     haptic->hwdata = NULL;
-    return;
 }
 
 void SDL_SYS_HapticQuit(void)
@@ -223,11 +222,9 @@ int SDL_SYS_HapticStopEffect(SDL_Haptic *haptic, struct haptic_effect *effect)
 
 void SDL_SYS_HapticDestroyEffect(SDL_Haptic *haptic, struct haptic_effect *effect)
 {
-    return;
 }
 
-int SDL_SYS_HapticGetEffectStatus(SDL_Haptic *haptic,
-                                  struct haptic_effect *effect)
+int SDL_SYS_HapticGetEffectStatus(SDL_Haptic *haptic, struct haptic_effect *effect)
 {
     return 0;
 }

+ 2 - 1
src/haptic/darwin/SDL_syshaptic.c

@@ -1204,8 +1204,9 @@ int SDL_SYS_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect,
     /* Check if it's infinite. */
     if (iterations == SDL_HAPTIC_INFINITY) {
         iter = FF_INFINITE;
-    } else
+    } else {
         iter = iterations;
+    }
 
     /* Run the effect. */
     ret = FFEffectStart(effect->hweffect->ref, iter, 0);

+ 3 - 4
src/haptic/linux/SDL_syshaptic.c

@@ -160,8 +160,7 @@ int SDL_SYS_HapticInit(void)
      */
     i = 0;
     for (j = 0; j < MAX_HAPTICS; ++j) {
-
-        SDL_snprintf(path, PATH_MAX, joydev_pattern, i++);
+        (void)SDL_snprintf(path, PATH_MAX, joydev_pattern, i++);
         MaybeAddDevice(path);
     }
 
@@ -673,9 +672,9 @@ static int SDL_SYS_ToDirection(Uint16 *dest, SDL_HapticDirection *src)
         break;
 
     case SDL_HAPTIC_CARTESIAN:
-        if (!src->dir[1])
+        if (!src->dir[1]) {
             *dest = (src->dir[0] >= 0 ? 0x4000 : 0xC000);
-        else if (!src->dir[0])
+        } else if (!src->dir[0]) {
             *dest = (src->dir[1] >= 0 ? 0x8000 : 0);
         else {
             float f = SDL_atan2(src->dir[1], src->dir[0]);    /* Ideally we'd use fixed point math instead of floats... */

+ 21 - 20
src/haptic/windows/SDL_dinputhaptic.c

@@ -664,10 +664,10 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
         dest->lpvTypeSpecificParams = constant;
 
         /* Generics */
-        dest->dwDuration = hap_constant->length * 1000; /* In microseconds. */
+        dest->dwDuration = hap_constant->length * 1000UL; /* In microseconds. */
         dest->dwTriggerButton = DIGetTriggerButton(hap_constant->button);
         dest->dwTriggerRepeatInterval = hap_constant->interval;
-        dest->dwStartDelay = hap_constant->delay * 1000; /* In microseconds. */
+        dest->dwStartDelay = hap_constant->delay * 1000UL; /* In microseconds. */
 
         /* Direction. */
         if (SDL_SYS_SetDirection(dest, &hap_constant->direction, dest->cAxes) < 0) {
@@ -680,9 +680,9 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
             dest->lpEnvelope = NULL;
         } else {
             envelope->dwAttackLevel = CCONVERT(hap_constant->attack_level);
-            envelope->dwAttackTime = hap_constant->attack_length * 1000;
+            envelope->dwAttackTime = hap_constant->attack_length * 1000UL;
             envelope->dwFadeLevel = CCONVERT(hap_constant->fade_level);
-            envelope->dwFadeTime = hap_constant->fade_length * 1000;
+            envelope->dwFadeTime = hap_constant->fade_length * 1000UL;
         }
 
         break;
@@ -710,10 +710,10 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
         dest->lpvTypeSpecificParams = periodic;
 
         /* Generics */
-        dest->dwDuration = hap_periodic->length * 1000; /* In microseconds. */
+        dest->dwDuration = hap_periodic->length * 1000UL; /* In microseconds. */
         dest->dwTriggerButton = DIGetTriggerButton(hap_periodic->button);
         dest->dwTriggerRepeatInterval = hap_periodic->interval;
-        dest->dwStartDelay = hap_periodic->delay * 1000; /* In microseconds. */
+        dest->dwStartDelay = hap_periodic->delay * 1000UL; /* In microseconds. */
 
         /* Direction. */
         if (SDL_SYS_SetDirection(dest, &hap_periodic->direction, dest->cAxes) < 0) {
@@ -726,9 +726,9 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
             dest->lpEnvelope = NULL;
         } else {
             envelope->dwAttackLevel = CCONVERT(hap_periodic->attack_level);
-            envelope->dwAttackTime = hap_periodic->attack_length * 1000;
+            envelope->dwAttackTime = hap_periodic->attack_length * 1000UL;
             envelope->dwFadeLevel = CCONVERT(hap_periodic->fade_level);
-            envelope->dwFadeTime = hap_periodic->fade_length * 1000;
+            envelope->dwFadeTime = hap_periodic->fade_length * 1000UL;
         }
 
         break;
@@ -761,10 +761,10 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
         dest->lpvTypeSpecificParams = condition;
 
         /* Generics */
-        dest->dwDuration = hap_condition->length * 1000; /* In microseconds. */
+        dest->dwDuration = hap_condition->length * 1000UL; /* In microseconds. */
         dest->dwTriggerButton = DIGetTriggerButton(hap_condition->button);
         dest->dwTriggerRepeatInterval = hap_condition->interval;
-        dest->dwStartDelay = hap_condition->delay * 1000; /* In microseconds. */
+        dest->dwStartDelay = hap_condition->delay * 1000UL; /* In microseconds. */
 
         /* Direction. */
         if (SDL_SYS_SetDirection(dest, &hap_condition->direction, dest->cAxes) < 0) {
@@ -792,10 +792,10 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
         dest->lpvTypeSpecificParams = ramp;
 
         /* Generics */
-        dest->dwDuration = hap_ramp->length * 1000; /* In microseconds. */
+        dest->dwDuration = hap_ramp->length * 1000UL; /* In microseconds. */
         dest->dwTriggerButton = DIGetTriggerButton(hap_ramp->button);
         dest->dwTriggerRepeatInterval = hap_ramp->interval;
-        dest->dwStartDelay = hap_ramp->delay * 1000; /* In microseconds. */
+        dest->dwStartDelay = hap_ramp->delay * 1000UL; /* In microseconds. */
 
         /* Direction. */
         if (SDL_SYS_SetDirection(dest, &hap_ramp->direction, dest->cAxes) < 0) {
@@ -808,9 +808,9 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
             dest->lpEnvelope = NULL;
         } else {
             envelope->dwAttackLevel = CCONVERT(hap_ramp->attack_level);
-            envelope->dwAttackTime = hap_ramp->attack_length * 1000;
+            envelope->dwAttackTime = hap_ramp->attack_length * 1000UL;
             envelope->dwFadeLevel = CCONVERT(hap_ramp->fade_level);
-            envelope->dwFadeTime = hap_ramp->fade_length * 1000;
+            envelope->dwFadeTime = hap_ramp->fade_length * 1000UL;
         }
 
         break;
@@ -825,7 +825,7 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
 
         /* Specifics */
         custom->cChannels = hap_custom->channels;
-        custom->dwSamplePeriod = hap_custom->period * 1000;
+        custom->dwSamplePeriod = hap_custom->period * 1000UL;
         custom->cSamples = hap_custom->samples;
         custom->rglForceData =
             SDL_malloc(sizeof(LONG) * custom->cSamples * custom->cChannels);
@@ -836,10 +836,10 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
         dest->lpvTypeSpecificParams = custom;
 
         /* Generics */
-        dest->dwDuration = hap_custom->length * 1000; /* In microseconds. */
+        dest->dwDuration = hap_custom->length * 1000UL; /* In microseconds. */
         dest->dwTriggerButton = DIGetTriggerButton(hap_custom->button);
         dest->dwTriggerRepeatInterval = hap_custom->interval;
-        dest->dwStartDelay = hap_custom->delay * 1000; /* In microseconds. */
+        dest->dwStartDelay = hap_custom->delay * 1000UL; /* In microseconds. */
 
         /* Direction. */
         if (SDL_SYS_SetDirection(dest, &hap_custom->direction, dest->cAxes) < 0) {
@@ -852,9 +852,9 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
             dest->lpEnvelope = NULL;
         } else {
             envelope->dwAttackLevel = CCONVERT(hap_custom->attack_level);
-            envelope->dwAttackTime = hap_custom->attack_length * 1000;
+            envelope->dwAttackTime = hap_custom->attack_length * 1000UL;
             envelope->dwFadeLevel = CCONVERT(hap_custom->fade_level);
-            envelope->dwFadeTime = hap_custom->fade_length * 1000;
+            envelope->dwFadeTime = hap_custom->fade_length * 1000UL;
         }
 
         break;
@@ -893,6 +893,7 @@ static void SDL_SYS_HapticFreeDIEFFECT(DIEFFECT *effect, int type)
 /*
  * Gets the effect type from the generic SDL haptic effect wrapper.
  */
+/* NOLINTNEXTLINE(readability-const-return-type): Can't fix Windows' headers */
 static REFGUID SDL_SYS_HapticEffectType(SDL_HapticEffect *effect)
 {
     switch (effect->type) {
@@ -1088,7 +1089,7 @@ int SDL_DINPUT_HapticSetGain(SDL_Haptic *haptic, int gain)
     dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
     dipdw.diph.dwObj = 0;
     dipdw.diph.dwHow = DIPH_DEVICE;
-    dipdw.dwData = gain * 100; /* 0 to 10,000 */
+    dipdw.dwData = (DWORD)gain * 100; /* 0 to 10,000 */
 
     /* Try to set the autocenter. */
     ret = IDirectInputDevice8_SetProperty(haptic->hwdata->device,

+ 2 - 2
src/haptic/windows/SDL_xinputhaptic.c

@@ -93,7 +93,7 @@ int SDL_XINPUT_HapticMaybeAddDevice(const DWORD dwUserid)
     /* !!! FIXME: I'm not bothering to query for a real name right now (can we even?) */
     {
         char buf[64];
-        SDL_snprintf(buf, sizeof(buf), "XInput Controller #%u", (unsigned int)(userid + 1));
+        (void)SDL_snprintf(buf, sizeof buf, "XInput Controller #%u", userid + 1);
         item->name = SDL_strdup(buf);
     }
 
@@ -204,7 +204,7 @@ static int SDL_XINPUT_HapticOpenFromUserIndex(SDL_Haptic *haptic, const Uint8 us
         return SDL_SetError("Couldn't create XInput haptic mutex");
     }
 
-    SDL_snprintf(threadName, sizeof(threadName), "SDLXInputDev%d", (int)userid);
+    (void)SDL_snprintf(threadName, sizeof threadName, "SDLXInputDev%u", userid);
     haptic->hwdata->thread = SDL_CreateThreadInternal(SDL_RunXInputHaptic, threadName, 64 * 1024, haptic->hwdata);
 
     if (haptic->hwdata->thread == NULL) {

+ 36 - 23
src/hidapi/SDL_hidapi.c

@@ -57,7 +57,6 @@
 #include "../core/linux/SDL_udev.h"
 #ifdef SDL_USE_LIBUDEV
 #include <poll.h>
-#include <unistd.h>
 #include "../core/linux/SDL_sandbox.h"
 #endif
 
@@ -69,6 +68,10 @@
 #include <sys/inotify.h>
 #endif
 
+#if defined(SDL_USE_LIBUDEV) || defined(HAVE_INOTIFY)
+#include <unistd.h>
+#endif
+
 #if defined(SDL_USE_LIBUDEV)
 typedef enum
 {
@@ -316,15 +319,15 @@ HIDAPI_InitializeDiscovery()
         SDL_HIDAPI_discovery.m_nUdevFd = -1;
 
         usyms = SDL_UDEV_GetUdevSyms();
-        if (usyms) {
+        if (usyms != NULL) {
             SDL_HIDAPI_discovery.m_pUdev = usyms->udev_new();
-        }
-        if (SDL_HIDAPI_discovery.m_pUdev) {
-            SDL_HIDAPI_discovery.m_pUdevMonitor = usyms->udev_monitor_new_from_netlink(SDL_HIDAPI_discovery.m_pUdev, "udev");
-            if (SDL_HIDAPI_discovery.m_pUdevMonitor) {
-                usyms->udev_monitor_enable_receiving(SDL_HIDAPI_discovery.m_pUdevMonitor);
-                SDL_HIDAPI_discovery.m_nUdevFd = usyms->udev_monitor_get_fd(SDL_HIDAPI_discovery.m_pUdevMonitor);
-                SDL_HIDAPI_discovery.m_bCanGetNotifications = SDL_TRUE;
+            if (SDL_HIDAPI_discovery.m_pUdev != NULL) {
+                SDL_HIDAPI_discovery.m_pUdevMonitor = usyms->udev_monitor_new_from_netlink(SDL_HIDAPI_discovery.m_pUdev, "udev");
+                if (SDL_HIDAPI_discovery.m_pUdevMonitor != NULL) {
+                    usyms->udev_monitor_enable_receiving(SDL_HIDAPI_discovery.m_pUdevMonitor);
+                    SDL_HIDAPI_discovery.m_nUdevFd = usyms->udev_monitor_get_fd(SDL_HIDAPI_discovery.m_pUdevMonitor);
+                    SDL_HIDAPI_discovery.m_bCanGetNotifications = SDL_TRUE;
+                }
             }
         }
     } else
@@ -1378,22 +1381,27 @@ SDL_hid_device *SDL_hid_open(unsigned short vendor_id, unsigned short product_id
     }
 
 #if HAVE_PLATFORM_BACKEND
-    if (udev_ctx &&
-        (pDevice = PLATFORM_hid_open(vendor_id, product_id, serial_number)) != NULL) {
-        return CreateHIDDeviceWrapper(pDevice, &PLATFORM_Backend);
+    if (udev_ctx) {
+        pDevice = PLATFORM_hid_open(vendor_id, product_id, serial_number);
+        if (pDevice != NULL) {
+            return CreateHIDDeviceWrapper(pDevice, &PLATFORM_Backend);
+        }
     }
 #endif /* HAVE_PLATFORM_BACKEND */
 
 #if HAVE_DRIVER_BACKEND
-    if ((pDevice = DRIVER_hid_open(vendor_id, product_id, serial_number)) != NULL) {
+    pDevice = DRIVER_hid_open(vendor_id, product_id, serial_number);
+    if (pDevice != NULL) {
         return CreateHIDDeviceWrapper(pDevice, &DRIVER_Backend);
     }
 #endif /* HAVE_DRIVER_BACKEND */
 
 #ifdef HAVE_LIBUSB
-    if (libusb_ctx.libhandle &&
-        (pDevice = LIBUSB_hid_open(vendor_id, product_id, serial_number)) != NULL) {
-        return CreateHIDDeviceWrapper(pDevice, &LIBUSB_Backend);
+    if (libusb_ctx.libhandle != NULL) {
+        pDevice = LIBUSB_hid_open(vendor_id, product_id, serial_number);
+        if (pDevice != NULL) {
+            return CreateHIDDeviceWrapper(pDevice, &LIBUSB_Backend);
+        }
     }
 #endif /* HAVE_LIBUSB */
 
@@ -1412,22 +1420,27 @@ SDL_hid_device *SDL_hid_open_path(const char *path, int bExclusive /* = false */
     }
 
 #if HAVE_PLATFORM_BACKEND
-    if (udev_ctx &&
-        (pDevice = PLATFORM_hid_open_path(path, bExclusive)) != NULL) {
-        return CreateHIDDeviceWrapper(pDevice, &PLATFORM_Backend);
+    if (udev_ctx) {
+        pDevice = PLATFORM_hid_open_path(path, bExclusive);
+        if (pDevice != NULL) {
+            return CreateHIDDeviceWrapper(pDevice, &PLATFORM_Backend);
+        }
     }
 #endif /* HAVE_PLATFORM_BACKEND */
 
 #if HAVE_DRIVER_BACKEND
-    if ((pDevice = DRIVER_hid_open_path(path, bExclusive)) != NULL) {
+    pDevice = DRIVER_hid_open_path(path, bExclusive);
+    if (pDevice != NULL) {
         return CreateHIDDeviceWrapper(pDevice, &DRIVER_Backend);
     }
 #endif /* HAVE_DRIVER_BACKEND */
 
 #ifdef HAVE_LIBUSB
-    if (libusb_ctx.libhandle &&
-        (pDevice = LIBUSB_hid_open_path(path, bExclusive)) != NULL) {
-        return CreateHIDDeviceWrapper(pDevice, &LIBUSB_Backend);
+    if (libusb_ctx.libhandle != NULL) {
+        pDevice = LIBUSB_hid_open_path(path, bExclusive);
+        if (pDevice != NULL) {
+            return CreateHIDDeviceWrapper(pDevice, &LIBUSB_Backend);
+        }
     }
 #endif /* HAVE_LIBUSB */
 

+ 39 - 37
src/joystick/SDL_gamecontroller.c

@@ -825,20 +825,21 @@ static const char *map_StringForControllerAxis[] = {
 /*
  * convert a string to its enum equivalent
  */
-SDL_GameControllerAxis SDL_GameControllerGetAxisFromString(const char *pchString)
+SDL_GameControllerAxis
+SDL_GameControllerGetAxisFromString(const char *str)
 {
     int entry;
 
-    if (pchString && (*pchString == '+' || *pchString == '-')) {
-        ++pchString;
+    if (str == NULL || str[0] == '\0') {
+        return SDL_CONTROLLER_AXIS_INVALID;
     }
 
-    if (pchString == NULL || !pchString[0]) {
-        return SDL_CONTROLLER_AXIS_INVALID;
+    if (*str == '+' || *str == '-') {
+        ++str;
     }
 
     for (entry = 0; map_StringForControllerAxis[entry]; ++entry) {
-        if (!SDL_strcasecmp(pchString, map_StringForControllerAxis[entry])) {
+        if (SDL_strcasecmp(str, map_StringForControllerAxis[entry]) == 0) {
             return (SDL_GameControllerAxis)entry;
         }
     }
@@ -884,15 +885,16 @@ static const char *map_StringForControllerButton[] = {
 /*
  * convert a string to its enum equivalent
  */
-SDL_GameControllerButton SDL_GameControllerGetButtonFromString(const char *pchString)
+SDL_GameControllerButton
+SDL_GameControllerGetButtonFromString(const char *str)
 {
     int entry;
-    if (pchString == NULL || !pchString[0]) {
+    if (str == NULL || str[0] == '\0') {
         return SDL_CONTROLLER_BUTTON_INVALID;
     }
 
     for (entry = 0; map_StringForControllerButton[entry]; ++entry) {
-        if (SDL_strcasecmp(pchString, map_StringForControllerButton[entry]) == 0) {
+        if (SDL_strcasecmp(str, map_StringForControllerButton[entry]) == 0) {
             return (SDL_GameControllerButton)entry;
         }
     }
@@ -902,10 +904,10 @@ SDL_GameControllerButton SDL_GameControllerGetButtonFromString(const char *pchSt
 /*
  * convert an enum to its string equivalent
  */
-const char *SDL_GameControllerGetStringForButton(SDL_GameControllerButton axis)
+const char *SDL_GameControllerGetStringForButton(SDL_GameControllerButton button)
 {
-    if (axis > SDL_CONTROLLER_BUTTON_INVALID && axis < SDL_CONTROLLER_BUTTON_MAX) {
-        return map_StringForControllerButton[axis];
+    if (button > SDL_CONTROLLER_BUTTON_INVALID && button < SDL_CONTROLLER_BUTTON_MAX) {
+        return map_StringForControllerButton[button];
     }
     return NULL;
 }
@@ -1071,7 +1073,7 @@ static void SDL_PrivateLoadButtonMapping(SDL_GameController *gamecontroller, Con
     gamecontroller->name = pControllerMapping->name;
     gamecontroller->num_bindings = 0;
     gamecontroller->mapping = pControllerMapping;
-    if (gamecontroller->joystick->naxes) {
+    if (gamecontroller->joystick->naxes != 0 && gamecontroller->last_match_axis != NULL) {
         SDL_memset(gamecontroller->last_match_axis, 0, gamecontroller->joystick->naxes * sizeof(*gamecontroller->last_match_axis));
     }
 
@@ -1351,13 +1353,13 @@ static void SDL_PrivateAppendToMappingString(char *mapping_string,
     SDL_strlcat(mapping_string, ":", mapping_string_len);
     switch (mapping->kind) {
     case EMappingKind_Button:
-        SDL_snprintf(buffer, sizeof(buffer), "b%i", mapping->target);
+        (void)SDL_snprintf(buffer, sizeof buffer, "b%i", mapping->target);
         break;
     case EMappingKind_Axis:
-        SDL_snprintf(buffer, sizeof(buffer), "a%i", mapping->target);
+        (void)SDL_snprintf(buffer, sizeof buffer, "a%i", mapping->target);
         break;
     case EMappingKind_Hat:
-        SDL_snprintf(buffer, sizeof(buffer), "h%i.%i", mapping->target >> 4, mapping->target & 0x0F);
+        (void)SDL_snprintf(buffer, sizeof buffer, "h%i.%i", mapping->target >> 4, mapping->target & 0x0F);
         break;
     default:
         SDL_assert(SDL_FALSE);
@@ -1385,7 +1387,7 @@ static ControllerMapping_t *SDL_PrivateGenerateAutomaticControllerMapping(const
             }
         }
     }
-    SDL_snprintf(mapping, sizeof(mapping), "none,%s,", name_string);
+    (void)SDL_snprintf(mapping, sizeof mapping, "none,%s,", name_string);
     SDL_PrivateAppendToMappingString(mapping, sizeof(mapping), "a", &raw_map->a);
     SDL_PrivateAppendToMappingString(mapping, sizeof(mapping), "b", &raw_map->b);
     SDL_PrivateAppendToMappingString(mapping, sizeof(mapping), "x", &raw_map->x);
@@ -1677,7 +1679,7 @@ static char *CreateMappingString(ControllerMapping_t *mapping, SDL_JoystickGUID
         return NULL;
     }
 
-    SDL_snprintf(pMappingString, needed, "%s,%s,%s", pchGUID, mapping->name, mapping->mapping);
+    (void)SDL_snprintf(pMappingString, needed, "%s,%s,%s", pchGUID, mapping->name, mapping->mapping);
 
     if (!SDL_strstr(mapping->mapping, SDL_CONTROLLER_PLATFORM_FIELD)) {
         if (mapping->mapping[SDL_strlen(mapping->mapping) - 1] != ',') {
@@ -1848,12 +1850,12 @@ int SDL_GameControllerInit(void)
  * Get the implementation dependent name of a controller
  */
 const char *
-SDL_GameControllerNameForIndex(int device_index)
+SDL_GameControllerNameForIndex(int joystick_index)
 {
-    ControllerMapping_t *pSupportedController = SDL_PrivateGetControllerMapping(device_index);
-    if (pSupportedController) {
+    ControllerMapping_t *pSupportedController = SDL_PrivateGetControllerMapping(joystick_index);
+    if (pSupportedController != NULL) {
         if (SDL_strcmp(pSupportedController->name, "*") == 0) {
-            return SDL_JoystickNameForIndex(device_index);
+            return SDL_JoystickNameForIndex(joystick_index);
         } else {
             return pSupportedController->name;
         }
@@ -1865,11 +1867,11 @@ SDL_GameControllerNameForIndex(int device_index)
  * Get the implementation dependent path of a controller
  */
 const char *
-SDL_GameControllerPathForIndex(int device_index)
+SDL_GameControllerPathForIndex(int joystick_index)
 {
-    ControllerMapping_t *pSupportedController = SDL_PrivateGetControllerMapping(device_index);
-    if (pSupportedController) {
-        return SDL_JoystickPathForIndex(device_index);
+    ControllerMapping_t *pSupportedController = SDL_PrivateGetControllerMapping(joystick_index);
+    if (pSupportedController != NULL) {
+        return SDL_JoystickPathForIndex(joystick_index);
     }
     return NULL;
 }
@@ -1910,7 +1912,7 @@ SDL_GameControllerMappingForDeviceIndex(int joystick_index)
             SDL_UnlockJoysticks();
             return NULL;
         }
-        SDL_snprintf(pMappingString, needed, "%s,%s,%s", pchGUID, mapping->name, mapping->mapping);
+        (void)SDL_snprintf(pMappingString, needed, "%s,%s,%s", pchGUID, mapping->name, mapping->mapping);
     }
     SDL_UnlockJoysticks();
     return pMappingString;
@@ -1933,10 +1935,10 @@ SDL_IsGameControllerNameAndGUID(const char *name, SDL_JoystickGUID guid)
  * Return 1 if the joystick at this device index is a supported controller
  */
 SDL_bool
-SDL_IsGameController(int device_index)
+SDL_IsGameController(int joystick_index)
 {
-    ControllerMapping_t *pSupportedController = SDL_PrivateGetControllerMapping(device_index);
-    if (pSupportedController) {
+    ControllerMapping_t *pSupportedController = SDL_PrivateGetControllerMapping(joystick_index);
+    if (pSupportedController != NULL) {
         return SDL_TRUE;
     }
     return SDL_FALSE;
@@ -2042,7 +2044,7 @@ SDL_bool SDL_ShouldIgnoreGameController(const char *name, SDL_JoystickGUID guid)
  * This function returns a controller identifier, or NULL if an error occurred.
  */
 SDL_GameController *
-SDL_GameControllerOpen(int device_index)
+SDL_GameControllerOpen(int joystick_index)
 {
     SDL_JoystickID instance_id;
     SDL_GameController *gamecontroller;
@@ -2053,8 +2055,8 @@ SDL_GameControllerOpen(int device_index)
 
     gamecontrollerlist = SDL_gamecontrollers;
     /* If the controller is already open, return it */
-    instance_id = SDL_JoystickGetDeviceInstanceID(device_index);
-    while (gamecontrollerlist) {
+    instance_id = SDL_JoystickGetDeviceInstanceID(joystick_index);
+    while (gamecontrollerlist != NULL) {
         if (instance_id == gamecontrollerlist->joystick->instance_id) {
             gamecontroller = gamecontrollerlist;
             ++gamecontroller->ref_count;
@@ -2065,9 +2067,9 @@ SDL_GameControllerOpen(int device_index)
     }
 
     /* Find a controller mapping */
-    pSupportedController = SDL_PrivateGetControllerMapping(device_index);
+    pSupportedController = SDL_PrivateGetControllerMapping(joystick_index);
     if (pSupportedController == NULL) {
-        SDL_SetError("Couldn't find mapping for device (%d)", device_index);
+        SDL_SetError("Couldn't find mapping for device (%d)", joystick_index);
         SDL_UnlockJoysticks();
         return NULL;
     }
@@ -2081,8 +2083,8 @@ SDL_GameControllerOpen(int device_index)
     }
     gamecontroller->magic = &gamecontroller_magic;
 
-    gamecontroller->joystick = SDL_JoystickOpen(device_index);
-    if (!gamecontroller->joystick) {
+    gamecontroller->joystick = SDL_JoystickOpen(joystick_index);
+    if (gamecontroller->joystick == NULL) {
         SDL_free(gamecontroller);
         SDL_UnlockJoysticks();
         return NULL;

+ 3 - 3
src/joystick/SDL_joystick.c

@@ -1881,7 +1881,7 @@ SDL_CreateJoystickName(Uint16 vendor, Uint16 product, const char *vendor_name, c
         len = (SDL_strlen(vendor_name) + 1 + SDL_strlen(product_name) + 1);
         name = (char *)SDL_malloc(len);
         if (name) {
-            SDL_snprintf(name, len, "%s %s", vendor_name, product_name);
+            (void)SDL_snprintf(name, len, "%s %s", vendor_name, product_name);
         }
     } else if (*product_name) {
         name = SDL_strdup(product_name);
@@ -1909,8 +1909,8 @@ SDL_CreateJoystickName(Uint16 vendor, Uint16 product, const char *vendor_name, c
         default:
             len = (6 + 1 + 6 + 1);
             name = (char *)SDL_malloc(len);
-            if (name) {
-                SDL_snprintf(name, len, "0x%.4x/0x%.4x", vendor, product);
+            if (name != NULL) {
+                (void)SDL_snprintf(name, len, "0x%.4x/0x%.4x", vendor, product);
             }
             break;
         }

+ 1 - 4
src/joystick/darwin/SDL_iokitjoystick.c

@@ -519,7 +519,6 @@ static SDL_bool JoystickAlreadyKnown(IOHIDDeviceRef ioHIDDeviceObject)
 static void JoystickDeviceWasAddedCallback(void *ctx, IOReturn res, void *sender, IOHIDDeviceRef ioHIDDeviceObject)
 {
     recDevice *device;
-    int device_index = 0;
     io_service_t ioservice;
 
     if (res != kIOReturnSuccess) {
@@ -570,12 +569,10 @@ static void JoystickDeviceWasAddedCallback(void *ctx, IOReturn res, void *sender
         recDevice *curdevice;
 
         curdevice = gpDeviceList;
-        while (curdevice->pNext) {
-            ++device_index;
+        while (curdevice->pNext != NULL) {
             curdevice = curdevice->pNext;
         }
         curdevice->pNext = device;
-        ++device_index; /* bump by one since we counted by pNext. */
     }
 
     SDL_PrivateJoystickAdded(device->instance_id);

+ 1 - 1
src/joystick/hidapi/SDL_hidapi_gamecube.c

@@ -233,7 +233,7 @@ static void HIDAPI_DriverGameCube_SetDevicePlayerIndex(SDL_HIDAPI_Device *device
 {
 }
 
-static void HIDAPI_DriverGameCube_HandleJoystickPacket(SDL_HIDAPI_Device *device, SDL_DriverGameCube_Context *ctx, Uint8 *packet, int size)
+static void HIDAPI_DriverGameCube_HandleJoystickPacket(SDL_HIDAPI_Device *device, SDL_DriverGameCube_Context *ctx, const Uint8 *packet, int size)
 {
     SDL_Joystick *joystick;
     Uint8 i, v;

+ 6 - 5
src/joystick/hidapi/SDL_hidapi_ps3.c

@@ -158,9 +158,9 @@ static SDL_bool HIDAPI_DriverPS3_InitDevice(SDL_HIDAPI_Device *device)
     /* Set the controller into report mode over USB */
     {
         Uint8 data[USB_PACKET_LENGTH];
-        int size;
 
-        if ((size = ReadFeatureReport(device->dev, 0xf2, data, 17)) < 0) {
+        int size = ReadFeatureReport(device->dev, 0xf2, data, 17);
+        if (size < 0) {
             SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
                          "HIDAPI_DriverPS3_InitDevice(): Couldn't read feature report 0xf2");
             return SDL_FALSE;
@@ -168,7 +168,8 @@ static SDL_bool HIDAPI_DriverPS3_InitDevice(SDL_HIDAPI_Device *device)
 #ifdef DEBUG_PS3_PROTOCOL
         HIDAPI_DumpPacket("PS3 0xF2 packet: size = %d", data, size);
 #endif
-        if ((size = ReadFeatureReport(device->dev, 0xf5, data, 8)) < 0) {
+        size = ReadFeatureReport(device->dev, 0xf5, data, 8);
+        if (size < 0) {
             SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
                          "HIDAPI_DriverPS3_InitDevice(): Couldn't read feature report 0xf5");
             return SDL_FALSE;
@@ -583,8 +584,8 @@ static SDL_bool HIDAPI_DriverPS3ThirdParty_IsSupportedDevice(SDL_HIDAPI_Device *
 
     if (SONY_THIRDPARTY_VENDOR(vendor_id)) {
         if (device && device->dev) {
-            if ((size = ReadFeatureReport(device->dev, 0x03, data, sizeof(data))) == 8 &&
-                data[2] == 0x26) {
+            size = ReadFeatureReport(device->dev, 0x03, data, sizeof data);
+            if (size == 8 && data[2] == 0x26) {
                 /* Supported third party controller */
                 return SDL_TRUE;
             } else {

+ 10 - 10
src/joystick/hidapi/SDL_hidapi_ps4.c

@@ -189,8 +189,8 @@ static SDL_bool HIDAPI_DriverPS4_IsSupportedDevice(SDL_HIDAPI_Device *device, co
 
     if (SONY_THIRDPARTY_VENDOR(vendor_id)) {
         if (device && device->dev) {
-            if ((size = ReadFeatureReport(device->dev, k_ePS4FeatureReportIdCapabilities, data, sizeof(data))) == 48 &&
-                data[2] == 0x27) {
+            size = ReadFeatureReport(device->dev, k_ePS4FeatureReportIdCapabilities, data, sizeof data);
+            if (size == 48 && data[2] == 0x27) {
                 /* Supported third party controller */
                 return SDL_TRUE;
             } else {
@@ -268,8 +268,8 @@ static SDL_bool HIDAPI_DriverPS4_InitDevice(SDL_HIDAPI_Device *device)
     if (ctx->is_dongle) {
         size = ReadFeatureReport(device->dev, k_ePS4FeatureReportIdSerialNumber, data, sizeof(data));
         if (size >= 7 && (data[1] || data[2] || data[3] || data[4] || data[5] || data[6])) {
-            SDL_snprintf(serial, sizeof(serial), "%.2x-%.2x-%.2x-%.2x-%.2x-%.2x",
-                         data[6], data[5], data[4], data[3], data[2], data[1]);
+            (void)SDL_snprintf(serial, sizeof serial, "%.2x-%.2x-%.2x-%.2x-%.2x-%.2x",
+                               data[6], data[5], data[4], data[3], data[2], data[1]);
         }
         device->is_bluetooth = SDL_FALSE;
         ctx->enhanced_mode = SDL_TRUE;
@@ -277,8 +277,8 @@ static SDL_bool HIDAPI_DriverPS4_InitDevice(SDL_HIDAPI_Device *device)
         /* This will fail if we're on Bluetooth */
         size = ReadFeatureReport(device->dev, k_ePS4FeatureReportIdSerialNumber, data, sizeof(data));
         if (size >= 7 && (data[1] || data[2] || data[3] || data[4] || data[5] || data[6])) {
-            SDL_snprintf(serial, sizeof(serial), "%.2x-%.2x-%.2x-%.2x-%.2x-%.2x",
-                         data[6], data[5], data[4], data[3], data[2], data[1]);
+            (void)SDL_snprintf(serial, sizeof serial, "%.2x-%.2x-%.2x-%.2x-%.2x-%.2x",
+                               data[6], data[5], data[4], data[3], data[2], data[1]);
             device->is_bluetooth = SDL_FALSE;
             ctx->enhanced_mode = SDL_TRUE;
         } else {
@@ -308,6 +308,7 @@ static SDL_bool HIDAPI_DriverPS4_InitDevice(SDL_HIDAPI_Device *device)
     SDL_Log("PS4 dongle = %s, bluetooth = %s\n", ctx->is_dongle ? "TRUE" : "FALSE", device->is_bluetooth ? "TRUE" : "FALSE");
 #endif
 
+    size = ReadFeatureReport(device->dev, k_ePS4FeatureReportIdCapabilities, data, sizeof data);
     /* Get the device capabilities */
     if (device->vendor_id == USB_VENDOR_SONY) {
         ctx->official_controller = SDL_TRUE;
@@ -315,8 +316,7 @@ static SDL_bool HIDAPI_DriverPS4_InitDevice(SDL_HIDAPI_Device *device)
         ctx->lightbar_supported = SDL_TRUE;
         ctx->vibration_supported = SDL_TRUE;
         ctx->touchpad_supported = SDL_TRUE;
-    } else if ((size = ReadFeatureReport(device->dev, k_ePS4FeatureReportIdCapabilities, data, sizeof(data))) == 48 &&
-               data[2] == 0x27) {
+    } else if (size == 48 && data[2] == 0x27) {
         Uint8 capabilities = data[4];
         Uint8 device_type = data[5];
 
@@ -1119,8 +1119,8 @@ static SDL_bool HIDAPI_DriverPS4_UpdateDevice(SDL_HIDAPI_Device *device)
                 char serial[18];
                 size = ReadFeatureReport(device->dev, k_ePS4FeatureReportIdSerialNumber, data, sizeof(data));
                 if (size >= 7 && (data[1] || data[2] || data[3] || data[4] || data[5] || data[6])) {
-                    SDL_snprintf(serial, sizeof(serial), "%.2x-%.2x-%.2x-%.2x-%.2x-%.2x",
-                                 data[6], data[5], data[4], data[3], data[2], data[1]);
+                    (void)SDL_snprintf(serial, sizeof serial, "%.2x-%.2x-%.2x-%.2x-%.2x-%.2x",
+                                       data[6], data[5], data[4], data[3], data[2], data[1]);
                     HIDAPI_SetDeviceSerial(device, serial);
                 }
                 HIDAPI_JoystickConnected(device, NULL);

+ 6 - 6
src/joystick/hidapi/SDL_hidapi_ps5.c

@@ -275,8 +275,8 @@ static SDL_bool HIDAPI_DriverPS5_IsSupportedDevice(SDL_HIDAPI_Device *device, co
 
     if (SONY_THIRDPARTY_VENDOR(vendor_id)) {
         if (device && device->dev) {
-            if ((size = ReadFeatureReport(device->dev, k_EPS5FeatureReportIdCapabilities, data, sizeof(data))) == 48 &&
-                data[2] == 0x28) {
+            size = ReadFeatureReport(device->dev, k_EPS5FeatureReportIdCapabilities, data, sizeof data);
+            if (size == 48 && data[2] == 0x28) {
                 /* Supported third party controller */
                 return SDL_TRUE;
             } else {
@@ -400,8 +400,8 @@ static SDL_bool HIDAPI_DriverPS5_InitDevice(SDL_HIDAPI_Device *device)
            This will also enable enhanced reports over Bluetooth
         */
         if (ReadFeatureReport(device->dev, k_EPS5FeatureReportIdSerialNumber, data, sizeof(data)) >= 7) {
-            SDL_snprintf(serial, sizeof(serial), "%.2x-%.2x-%.2x-%.2x-%.2x-%.2x",
-                         data[6], data[5], data[4], data[3], data[2], data[1]);
+            (void)SDL_snprintf(serial, sizeof serial, "%.2x-%.2x-%.2x-%.2x-%.2x-%.2x",
+                               data[6], data[5], data[4], data[3], data[2], data[1]);
         }
 
         /* Read the firmware version
@@ -412,6 +412,7 @@ static SDL_bool HIDAPI_DriverPS5_InitDevice(SDL_HIDAPI_Device *device)
         }
     }
 
+    size = ReadFeatureReport(device->dev, k_EPS5FeatureReportIdCapabilities, data, sizeof data);
     /* Get the device capabilities */
     if (device->vendor_id == USB_VENDOR_SONY) {
         ctx->sensors_supported = SDL_TRUE;
@@ -419,8 +420,7 @@ static SDL_bool HIDAPI_DriverPS5_InitDevice(SDL_HIDAPI_Device *device)
         ctx->vibration_supported = SDL_TRUE;
         ctx->playerled_supported = SDL_TRUE;
         ctx->touchpad_supported = SDL_TRUE;
-    } else if ((size = ReadFeatureReport(device->dev, k_EPS5FeatureReportIdCapabilities, data, sizeof(data))) == 48 &&
-               data[2] == 0x28) {
+    } else if (size == 48 && data[2] == 0x28) {
         Uint8 capabilities = data[4];
         Uint8 capabilities2 = data[20];
         Uint8 device_type = data[5];

+ 1 - 1
src/joystick/hidapi/SDL_hidapi_shield.c

@@ -368,7 +368,7 @@ static void HIDAPI_DriverShield_HandleStatePacketV103(SDL_Joystick *joystick, SD
 #undef clamp
 #define clamp(val, min, max) (((val) > (max)) ? (max) : (((val) < (min)) ? (min) : (val)))
 
-static void HIDAPI_DriverShield_HandleTouchPacketV103(SDL_Joystick *joystick, SDL_DriverShield_Context *ctx, Uint8 *data, int size)
+static void HIDAPI_DriverShield_HandleTouchPacketV103(SDL_Joystick *joystick, SDL_DriverShield_Context *ctx, const Uint8 *data, int size)
 {
     Uint8 touchpad_state;
     float touchpad_x, touchpad_y;

+ 16 - 11
src/joystick/hidapi/SDL_hidapi_steam.c

@@ -244,7 +244,7 @@ static int WriteSegmentToSteamControllerPacketAssembler(SteamControllerPacketAss
         }
 
         if (nSegmentLength != MAX_REPORT_SEGMENT_SIZE) {
-            printf("Bad segment size! %d\n", (int)nSegmentLength);
+            printf("Bad segment size! %d\n", nSegmentLength);
             hexdump(pSegment, nSegmentLength);
             ResetSteamControllerPacketAssembler(pAssembler);
             return -1;
@@ -365,10 +365,11 @@ static int GetFeatureReport(SDL_hid_device *dev, unsigned char uBuffer[65])
             HEXDUMP(uSegmentBuffer, nRet);
 
             // Zero retry counter if we got data
-            if (nRet > 2 && (uSegmentBuffer[ucDataStartOffset + 1] & REPORT_SEGMENT_DATA_FLAG))
+            if (nRet > 2 && (uSegmentBuffer[ucDataStartOffset + 1] & REPORT_SEGMENT_DATA_FLAG)) {
                 nRetries = 0;
-            else
+            } else {
                 nRetries++;
+            }
 
             if (nRet > 0) {
                 int nPacketLength = WriteSegmentToSteamControllerPacketAssembler(&assembler,
@@ -752,19 +753,21 @@ static void FormatStatePacketUntilGyro(SteamControllerStateInternal_t *pState, V
     RotatePad(&nLeftPadX, &nLeftPadY, -flRotationAngle);
     RotatePad(&nRightPadX, &nRightPadY, flRotationAngle);
 
-    if (pState->ulButtons & STEAM_LEFTPAD_FINGERDOWN_MASK)
+    if (pState->ulButtons & STEAM_LEFTPAD_FINGERDOWN_MASK) {
         nPadOffset = 1000;
-    else
+    } else {
         nPadOffset = 0;
+    }
 
     pState->sLeftPadX = clamp(nLeftPadX + nPadOffset, SDL_MIN_SINT16, SDL_MAX_SINT16);
     pState->sLeftPadY = clamp(nLeftPadY + nPadOffset, SDL_MIN_SINT16, SDL_MAX_SINT16);
 
     nPadOffset = 0;
-    if (pState->ulButtons & STEAM_RIGHTPAD_FINGERDOWN_MASK)
+    if (pState->ulButtons & STEAM_RIGHTPAD_FINGERDOWN_MASK) {
         nPadOffset = 1000;
-    else
+    } else {
         nPadOffset = 0;
+    }
 
     pState->sRightPadX = clamp(nRightPadX + nPadOffset, SDL_MIN_SINT16, SDL_MAX_SINT16);
     pState->sRightPadY = clamp(nRightPadY + nPadOffset, SDL_MIN_SINT16, SDL_MAX_SINT16);
@@ -811,10 +814,11 @@ static bool UpdateBLESteamControllerState(const uint8_t *pData, int nDataSize, S
         int nLength = sizeof(pState->sLeftPadX) + sizeof(pState->sLeftPadY);
         int nPadOffset;
         SDL_memcpy(&pState->sLeftPadX, pData, nLength);
-        if (pState->ulButtons & STEAM_LEFTPAD_FINGERDOWN_MASK)
+        if (pState->ulButtons & STEAM_LEFTPAD_FINGERDOWN_MASK) {
             nPadOffset = 1000;
-        else
+        } else {
             nPadOffset = 0;
+        }
 
         RotatePadShort(&pState->sLeftPadX, &pState->sLeftPadY, -flRotationAngle);
         pState->sLeftPadX = clamp(pState->sLeftPadX + nPadOffset, SDL_MIN_SINT16, SDL_MAX_SINT16);
@@ -827,10 +831,11 @@ static bool UpdateBLESteamControllerState(const uint8_t *pData, int nDataSize, S
 
         SDL_memcpy(&pState->sRightPadX, pData, nLength);
 
-        if (pState->ulButtons & STEAM_RIGHTPAD_FINGERDOWN_MASK)
+        if (pState->ulButtons & STEAM_RIGHTPAD_FINGERDOWN_MASK) {
             nPadOffset = 1000;
-        else
+        } else {
             nPadOffset = 0;
+        }
 
         RotatePadShort(&pState->sRightPadX, &pState->sRightPadY, flRotationAngle);
         pState->sRightPadX = clamp(pState->sRightPadX + nPadOffset, SDL_MIN_SINT16, SDL_MAX_SINT16);

+ 12 - 11
src/joystick/hidapi/SDL_hidapi_switch.c

@@ -829,9 +829,9 @@ static SDL_bool LoadIMUCalibration(SDL_DriverSwitch_Context *ctx)
     }
 
     /* Accelerometer scale */
-    ctx->m_IMUScaleData.fAccelScaleX = SWITCH_ACCEL_SCALE_MULT / (float)(SWITCH_ACCEL_SCALE_OFFSET - (float)sAccelRawX) * SDL_STANDARD_GRAVITY;
-    ctx->m_IMUScaleData.fAccelScaleY = SWITCH_ACCEL_SCALE_MULT / (float)(SWITCH_ACCEL_SCALE_OFFSET - (float)sAccelRawY) * SDL_STANDARD_GRAVITY;
-    ctx->m_IMUScaleData.fAccelScaleZ = SWITCH_ACCEL_SCALE_MULT / (float)(SWITCH_ACCEL_SCALE_OFFSET - (float)sAccelRawZ) * SDL_STANDARD_GRAVITY;
+    ctx->m_IMUScaleData.fAccelScaleX = SWITCH_ACCEL_SCALE_MULT / (SWITCH_ACCEL_SCALE_OFFSET - (float)sAccelRawX) * SDL_STANDARD_GRAVITY;
+    ctx->m_IMUScaleData.fAccelScaleY = SWITCH_ACCEL_SCALE_MULT / (SWITCH_ACCEL_SCALE_OFFSET - (float)sAccelRawY) * SDL_STANDARD_GRAVITY;
+    ctx->m_IMUScaleData.fAccelScaleZ = SWITCH_ACCEL_SCALE_MULT / (SWITCH_ACCEL_SCALE_OFFSET - (float)sAccelRawZ) * SDL_STANDARD_GRAVITY;
 
     /* Gyro scale */
     ctx->m_IMUScaleData.fGyroScaleX = SWITCH_GYRO_SCALE_MULT / (float)(SWITCH_GYRO_SCALE_OFFSET - (float)sGyroRawX) * (float)M_PI / 180.0f;
@@ -1177,13 +1177,13 @@ static void UpdateDeviceIdentity(SDL_HIDAPI_Device *device)
     }
     device->guid.data[15] = ctx->m_eControllerType;
 
-    SDL_snprintf(serial, sizeof(serial), "%.2x-%.2x-%.2x-%.2x-%.2x-%.2x",
-                 ctx->m_rgucMACAddress[0],
-                 ctx->m_rgucMACAddress[1],
-                 ctx->m_rgucMACAddress[2],
-                 ctx->m_rgucMACAddress[3],
-                 ctx->m_rgucMACAddress[4],
-                 ctx->m_rgucMACAddress[5]);
+    (void)SDL_snprintf(serial, sizeof serial, "%.2x-%.2x-%.2x-%.2x-%.2x-%.2x",
+                       ctx->m_rgucMACAddress[0],
+                       ctx->m_rgucMACAddress[1],
+                       ctx->m_rgucMACAddress[2],
+                       ctx->m_rgucMACAddress[3],
+                       ctx->m_rgucMACAddress[4],
+                       ctx->m_rgucMACAddress[5]);
     HIDAPI_SetDeviceSerial(device, serial);
 }
 
@@ -1717,7 +1717,8 @@ static void HandleSimpleControllerState(SDL_Joystick *joystick, SDL_DriverSwitch
     ctx->m_lastSimpleState = *packet;
 }
 
-static void SendSensorUpdate(SDL_Joystick *joystick, SDL_DriverSwitch_Context *ctx, SDL_SensorType type, Uint64 timestamp_us, Sint16 *values)
+static void
+SendSensorUpdate(SDL_Joystick *joystick, SDL_DriverSwitch_Context *ctx, SDL_SensorType type, Uint64 timestamp_us, const Sint16 *values)
 {
     float data[3];
 

+ 5 - 5
src/joystick/hidapi/SDL_hidapi_xboxone.c

@@ -214,7 +214,7 @@ static void SetInitState(SDL_DriverXboxOne_Context *ctx, SDL_XboxOneInitState st
     ctx->init_state = state;
 }
 
-static void SendAckIfNeeded(SDL_HIDAPI_Device *device, Uint8 *data, int size)
+static void SendAckIfNeeded(SDL_HIDAPI_Device *device, const Uint8 *data, int size)
 {
 #if defined(__WIN32__) || defined(__WINGDK__)
     /* The Windows driver is taking care of acks */
@@ -812,7 +812,7 @@ static void HIDAPI_DriverXboxOne_HandleStatusPacket(SDL_Joystick *joystick, SDL_
     }
 }
 
-static void HIDAPI_DriverXboxOne_HandleModePacket(SDL_Joystick *joystick, SDL_DriverXboxOne_Context *ctx, Uint8 *data, int size)
+static void HIDAPI_DriverXboxOne_HandleModePacket(SDL_Joystick *joystick, SDL_DriverXboxOne_Context *ctx, const Uint8 *data, int size)
 {
     SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_GUIDE, (data[4] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
 }
@@ -820,7 +820,7 @@ static void HIDAPI_DriverXboxOne_HandleModePacket(SDL_Joystick *joystick, SDL_Dr
 /*
  * Xbox One S with firmware 3.1.1221 uses a 16 byte packet and the GUIDE button in a separate packet
  */
-static void HIDAPI_DriverXboxOneBluetooth_HandleButtons16(SDL_Joystick *joystick, SDL_DriverXboxOne_Context *ctx, Uint8 *data, int size)
+static void HIDAPI_DriverXboxOneBluetooth_HandleButtons16(SDL_Joystick *joystick, SDL_DriverXboxOne_Context *ctx, const Uint8 *data, int size)
 {
     if (ctx->last_state[14] != data[14]) {
         SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_A, (data[14] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
@@ -1022,13 +1022,13 @@ static void HIDAPI_DriverXboxOneBluetooth_HandleStatePacket(SDL_Joystick *joysti
     SDL_memcpy(ctx->last_state, data, SDL_min(size, sizeof(ctx->last_state)));
 }
 
-static void HIDAPI_DriverXboxOneBluetooth_HandleGuidePacket(SDL_Joystick *joystick, SDL_DriverXboxOne_Context *ctx, Uint8 *data, int size)
+static void HIDAPI_DriverXboxOneBluetooth_HandleGuidePacket(SDL_Joystick *joystick, SDL_DriverXboxOne_Context *ctx, const Uint8 *data, int size)
 {
     ctx->has_guide_packet = SDL_TRUE;
     SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_GUIDE, (data[1] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
 }
 
-static void HIDAPI_DriverXboxOneBluetooth_HandleBatteryPacket(SDL_Joystick *joystick, SDL_DriverXboxOne_Context *ctx, Uint8 *data, int size)
+static void HIDAPI_DriverXboxOneBluetooth_HandleBatteryPacket(SDL_Joystick *joystick, SDL_DriverXboxOne_Context *ctx, const Uint8 *data, int size)
 {
     Uint8 flags = data[1];
     SDL_bool on_usb = (((flags & 0x0C) >> 2) == 0);

+ 4 - 6
src/joystick/hidapi/SDL_hidapijoystick.c

@@ -105,12 +105,13 @@ void HIDAPI_DumpPacket(const char *prefix, const Uint8 *data, int size)
     int start = 0, amount = size;
 
     buffer = (char *)SDL_malloc(length);
-    SDL_snprintf(buffer, length, prefix, size);
+    (void)SDL_snprintf(buffer, length, prefix, size);
     for (i = start; i < start + amount; ++i) {
+        size_t current_len = SDL_strlen(buffer);
         if ((i % 8) == 0) {
-            SDL_snprintf(&buffer[SDL_strlen(buffer)], length - SDL_strlen(buffer), "\n%.2d:      ", i);
+            (void)SDL_snprintf(&buffer[current_len], length - current_len, "\n%.2d:      ", i);
         }
-        SDL_snprintf(&buffer[SDL_strlen(buffer)], length - SDL_strlen(buffer), " 0x%.2x", data[i]);
+        (void)SDL_snprintf(&buffer[current_len], length - current_len, " 0x%.2x", data[i]);
     }
     SDL_strlcat(buffer, "\n", length);
     SDL_Log("%s", buffer);
@@ -384,7 +385,6 @@ static void HIDAPI_SetupDeviceDriver(SDL_HIDAPI_Device *device, SDL_bool *remove
 
             /* Make sure the device didn't get removed while opening the HID path */
             for (curr = SDL_HIDAPI_devices; curr && curr != device; curr = curr->next) {
-                continue;
             }
             if (curr == NULL) {
                 *removed = SDL_TRUE;
@@ -718,7 +718,6 @@ static SDL_HIDAPI_Device *HIDAPI_AddDevice(const struct SDL_hid_device_info *inf
     SDL_bool removed;
 
     for (curr = SDL_HIDAPI_devices, last = NULL; curr; last = curr, curr = curr->next) {
-        continue;
     }
 
     device = (SDL_HIDAPI_Device *)SDL_calloc(1, sizeof(*device));
@@ -985,7 +984,6 @@ check_removed:
 
     /* See if we can create any combined Joy-Con controllers */
     while (HIDAPI_CreateCombinedJoyCons()) {
-        continue;
     }
 
     SDL_UnlockJoysticks();

+ 16 - 15
src/joystick/iphoneos/SDL_mfijoystick.m

@@ -1310,10 +1310,10 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
 @end
 
 @interface SDL_RumbleContext : NSObject
-@property(nonatomic, strong) SDL_RumbleMotor *m_low_frequency_motor;
-@property(nonatomic, strong) SDL_RumbleMotor *m_high_frequency_motor;
-@property(nonatomic, strong) SDL_RumbleMotor *m_left_trigger_motor;
-@property(nonatomic, strong) SDL_RumbleMotor *m_right_trigger_motor;
+@property(nonatomic, strong) SDL_RumbleMotor *lowFrequencyMotor;
+@property(nonatomic, strong) SDL_RumbleMotor *highFrequencyMotor;
+@property(nonatomic, strong) SDL_RumbleMotor *leftTriggerMotor;
+@property(nonatomic, strong) SDL_RumbleMotor *rightTriggerMotor;
 @end
 
 @implementation SDL_RumbleContext
@@ -1326,10 +1326,10 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
               RightTriggerMotor:(SDL_RumbleMotor *)right_trigger_motor
 {
     self = [super init];
-    self.m_low_frequency_motor = low_frequency_motor;
-    self.m_high_frequency_motor = high_frequency_motor;
-    self.m_left_trigger_motor = left_trigger_motor;
-    self.m_right_trigger_motor = right_trigger_motor;
+    self.lowFrequencyMotor = low_frequency_motor;
+    self.highFrequencyMotor = high_frequency_motor;
+    self.leftTriggerMotor = left_trigger_motor;
+    self.rightTriggerMotor = right_trigger_motor;
     return self;
 }
 
@@ -1337,8 +1337,8 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
 {
     int result = 0;
 
-    result += [self.m_low_frequency_motor setIntensity:((float)low_frequency_rumble / 65535.0f)];
-    result += [self.m_high_frequency_motor setIntensity:((float)high_frequency_rumble / 65535.0f)];
+    result += [self.lowFrequencyMotor setIntensity:((float)low_frequency_rumble / 65535.0f)];
+    result += [self.highFrequencyMotor setIntensity:((float)high_frequency_rumble / 65535.0f)];
     return ((result < 0) ? -1 : 0);
 }
 
@@ -1346,9 +1346,9 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
 {
     int result = 0;
 
-    if (self.m_left_trigger_motor && self.m_right_trigger_motor) {
-        result += [self.m_left_trigger_motor setIntensity:((float)left_rumble / 65535.0f)];
-        result += [self.m_right_trigger_motor setIntensity:((float)right_rumble / 65535.0f)];
+    if (self.leftTriggerMotor && self.rightTriggerMotor) {
+        result += [self.leftTriggerMotor setIntensity:((float)left_rumble / 65535.0f)];
+        result += [self.rightTriggerMotor setIntensity:((float)right_rumble / 65535.0f)];
     } else {
         result = SDL_Unsupported();
     }
@@ -1357,8 +1357,8 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
 
 - (void)cleanup
 {
-    [self.m_low_frequency_motor cleanup];
-    [self.m_high_frequency_motor cleanup];
+    [self.lowFrequencyMotor cleanup];
+    [self.highFrequencyMotor cleanup];
 }
 
 @end
@@ -1675,6 +1675,7 @@ SDL_bool IOS_SupportedHIDDevice(IOHIDDeviceRef device)
 #endif
 
 #if defined(SDL_JOYSTICK_MFI) && defined(ENABLE_PHYSICAL_INPUT_PROFILE)
+/* NOLINTNEXTLINE(readability-non-const-parameter): getCString takes a non-const char* */
 static void GetAppleSFSymbolsNameForElement(GCControllerElement *element, char *name)
 {
     if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {

+ 3 - 3
src/joystick/linux/SDL_sysjoystick.c

@@ -565,7 +565,7 @@ static void LINUX_InotifyJoystickDetect(void)
     while (remain > 0) {
         if (buf.event.len > 0) {
             if (IsJoystickDeviceNode(buf.event.name)) {
-                SDL_snprintf(path, SDL_arraysize(path), "/dev/input/%s", buf.event.name);
+                (void)SDL_snprintf(path, SDL_arraysize(path), "/dev/input/%s", buf.event.name);
 
                 if (buf.event.mask & (IN_CREATE | IN_MOVED_TO | IN_ATTRIB)) {
                     MaybeAddDevice(path);
@@ -592,7 +592,7 @@ static int get_event_joystick_index(int event)
     struct dirent **entries = NULL;
     char path[PATH_MAX];
 
-    SDL_snprintf(path, SDL_arraysize(path), "/sys/class/input/event%d/device", event);
+    (void)SDL_snprintf(path, SDL_arraysize(path), "/sys/class/input/event%d/device", event);
     count = scandir(path, &entries, NULL, alphasort);
     for (i = 0; i < count; ++i) {
         if (SDL_strncmp(entries[i]->d_name, "js", 2) == 0) {
@@ -665,7 +665,7 @@ static void LINUX_FallbackJoystickDetect(void)
                 qsort(entries, count, sizeof(*entries), sort_entries);
             }
             for (i = 0; i < count; ++i) {
-                SDL_snprintf(path, SDL_arraysize(path), "/dev/input/%s", entries[i]->d_name);
+                (void)SDL_snprintf(path, SDL_arraysize(path), "/dev/input/%s", entries[i]->d_name);
                 MaybeAddDevice(path);
 
                 free(entries[i]); /* This should NOT be SDL_free() */

+ 0 - 1
src/joystick/virtual/SDL_virtualjoystick.c

@@ -228,7 +228,6 @@ int SDL_JoystickAttachVirtualInner(const SDL_VirtualJoystickDesc *desc)
         joystick_hwdata *last;
 
         for (last = g_VJoys; last->next; last = last->next) {
-            continue;
         }
         last->next = hwdata;
     } else {

+ 7 - 7
src/joystick/windows/SDL_dinputjoystick.c

@@ -623,19 +623,19 @@ static BOOL CALLBACK EnumDevObjectsCallback(LPCDIDEVICEOBJECTINSTANCE pDeviceObj
 
         in->type = AXIS;
         in->num = joystick->naxes;
-        if (!SDL_memcmp(&pDeviceObject->guidType, &GUID_XAxis, sizeof(pDeviceObject->guidType)))
+        if (SDL_memcmp(&pDeviceObject->guidType, &GUID_XAxis, sizeof pDeviceObject->guidType) == 0) {
             in->ofs = DIJOFS_X;
-        else if (!SDL_memcmp(&pDeviceObject->guidType, &GUID_YAxis, sizeof(pDeviceObject->guidType)))
+        } else if (SDL_memcmp(&pDeviceObject->guidType, &GUID_YAxis, sizeof pDeviceObject->guidType) == 0) {
             in->ofs = DIJOFS_Y;
-        else if (!SDL_memcmp(&pDeviceObject->guidType, &GUID_ZAxis, sizeof(pDeviceObject->guidType)))
+        } else if (SDL_memcmp(&pDeviceObject->guidType, &GUID_ZAxis, sizeof pDeviceObject->guidType) == 0) {
             in->ofs = DIJOFS_Z;
-        else if (!SDL_memcmp(&pDeviceObject->guidType, &GUID_RxAxis, sizeof(pDeviceObject->guidType)))
+        } else if (SDL_memcmp(&pDeviceObject->guidType, &GUID_RxAxis, sizeof pDeviceObject->guidType) == 0) {
             in->ofs = DIJOFS_RX;
-        else if (!SDL_memcmp(&pDeviceObject->guidType, &GUID_RyAxis, sizeof(pDeviceObject->guidType)))
+        } else if (SDL_memcmp(&pDeviceObject->guidType, &GUID_RyAxis, sizeof pDeviceObject->guidType) == 0) {
             in->ofs = DIJOFS_RY;
-        else if (!SDL_memcmp(&pDeviceObject->guidType, &GUID_RzAxis, sizeof(pDeviceObject->guidType)))
+        } else if (SDL_memcmp(&pDeviceObject->guidType, &GUID_RzAxis, sizeof pDeviceObject->guidType) == 0) {
             in->ofs = DIJOFS_RZ;
-        else if (!SDL_memcmp(&pDeviceObject->guidType, &GUID_Slider, sizeof(pDeviceObject->guidType))) {
+        } else if (SDL_memcmp(&pDeviceObject->guidType, &GUID_Slider, sizeof pDeviceObject->guidType) == 0) {
             in->ofs = DIJOFS_SLIDER(joystick->hwdata->NumSliders);
             ++joystick->hwdata->NumSliders;
         } else {

+ 4 - 4
src/joystick/windows/SDL_rawinputjoystick.c

@@ -730,8 +730,8 @@ static void RAWINPUT_AddDevice(HANDLE hDevice)
     /* Don't take devices handled by HIDAPI */
     CHECK(!HIDAPI_IsDevicePresent((Uint16)rdi.hid.dwVendorId, (Uint16)rdi.hid.dwProductId, (Uint16)rdi.hid.dwVersionNumber, ""));
 #endif
-
-    CHECK(device = (SDL_RAWINPUT_Device *)SDL_calloc(1, sizeof(SDL_RAWINPUT_Device)));
+    device = (SDL_RAWINPUT_Device *)SDL_calloc(1, sizeof(SDL_RAWINPUT_Device));
+    CHECK(device);
     device->hDevice = hDevice;
     device->vendor_id = (Uint16)rdi.hid.dwVendorId;
     device->product_id = (Uint16)rdi.hid.dwProductId;
@@ -742,7 +742,8 @@ static void RAWINPUT_AddDevice(HANDLE hDevice)
     /* Get HID Top-Level Collection Preparsed Data */
     size = 0;
     CHECK(GetRawInputDeviceInfoA(hDevice, RIDI_PREPARSEDDATA, NULL, &size) != (UINT)-1);
-    CHECK(device->preparsed_data = (PHIDP_PREPARSED_DATA)SDL_calloc(size, sizeof(BYTE)));
+    device->preparsed_data = (PHIDP_PREPARSED_DATA)SDL_calloc(size, sizeof(BYTE));
+    CHECK(device->preparsed_data);
     CHECK(GetRawInputDeviceInfoA(hDevice, RIDI_PREPARSEDDATA, device->preparsed_data, &size) != (UINT)-1);
 
     hFile = CreateFileA(dev_name, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
@@ -786,7 +787,6 @@ static void RAWINPUT_AddDevice(HANDLE hDevice)
     /* Add it to the list */
     RAWINPUT_AcquireDevice(device);
     for (curr = SDL_RAWINPUT_devices, last = NULL; curr; last = curr, curr = curr->next) {
-        continue;
     }
     if (last) {
         last->next = device;

+ 4 - 2
src/joystick/windows/SDL_windows_gaming_input.c

@@ -189,7 +189,7 @@ static SDL_bool SDL_IsXInputDevice(Uint16 vendor, Uint16 product)
             continue;
         }
 
-        SDL_snprintf(devVidPidString, sizeof(devVidPidString), "VID_%04X&PID_%04X", vendor, product);
+        (void)SDL_snprintf(devVidPidString, sizeof devVidPidString, "VID_%04X&PID_%04X", vendor, product);
 
         while (CM_Get_Parent(&devNode, devNode, 0) == CR_SUCCESS) {
             char deviceId[MAX_DEVICE_ID_LEN];
@@ -237,7 +237,7 @@ static HRESULT STDMETHODCALLTYPE IEventHandler_CRawGameControllerVtbl_QueryInter
 static ULONG STDMETHODCALLTYPE IEventHandler_CRawGameControllerVtbl_AddRef(__FIEventHandler_1_Windows__CGaming__CInput__CRawGameController *This)
 {
     RawGameControllerDelegate *self = (RawGameControllerDelegate *)This;
-    return SDL_AtomicAdd(&self->refcount, 1) + 1;
+    return SDL_AtomicAdd(&self->refcount, 1) + 1UL;
 }
 
 static ULONG STDMETHODCALLTYPE IEventHandler_CRawGameControllerVtbl_Release(__FIEventHandler_1_Windows__CGaming__CInput__CRawGameController *This)
@@ -393,6 +393,8 @@ static HRESULT STDMETHODCALLTYPE IEventHandler_CRawGameControllerVtbl_InvokeAdde
                 wgi.controllers = controllers;
 
                 SDL_PrivateJoystickAdded(joystickID);
+            } else {
+                SDL_free(name);
             }
         }
 

+ 3 - 3
src/joystick/windows/SDL_windowsjoystick.c

@@ -177,7 +177,7 @@ static DWORD CALLBACK SDL_DeviceNotificationFunc(HCMNOTIFICATION hNotify, PVOID
 static void SDL_CleanupDeviceNotificationFunc(void)
 {
     if (cfgmgr32_lib_handle) {
-        if (s_DeviceNotificationFuncHandle) {
+        if (s_DeviceNotificationFuncHandle != NULL && CM_Unregister_Notification != NULL) {
             CM_Unregister_Notification(s_DeviceNotificationFuncHandle);
             s_DeviceNotificationFuncHandle = NULL;
         }
@@ -294,8 +294,8 @@ static int SDL_CreateDeviceNotification(SDL_DeviceNotificationData *data)
         return -1;
     }
 
-    data->messageWindow = (HWND)CreateWindowEx(0, TEXT("Message"), NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, NULL);
-    if (!data->messageWindow) {
+    data->messageWindow = CreateWindowEx(0, TEXT("Message"), NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, NULL);
+    if (data->messageWindow == NULL) {
         WIN_SetError("Failed to create message window for joystick autodetect");
         SDL_CleanupDeviceNotification(data);
         return -1;

+ 14 - 14
src/joystick/windows/SDL_xinputjoystick.c

@@ -86,37 +86,37 @@ static const char *GetXInputName(const Uint8 userid, BYTE SubType)
     static char name[32];
 
     if (SDL_XInputUseOldJoystickMapping()) {
-        SDL_snprintf(name, sizeof(name), "X360 Controller #%u", 1 + userid);
+        (void)SDL_snprintf(name, sizeof name, "X360 Controller #%u", 1 + userid);
     } else {
         switch (SubType) {
         case XINPUT_DEVSUBTYPE_GAMEPAD:
-            SDL_snprintf(name, sizeof(name), "XInput Controller #%u", 1 + userid);
+            (void)SDL_snprintf(name, sizeof name, "XInput Controller #%u", 1 + userid);
             break;
         case XINPUT_DEVSUBTYPE_WHEEL:
-            SDL_snprintf(name, sizeof(name), "XInput Wheel #%u", 1 + userid);
+            (void)SDL_snprintf(name, sizeof name, "XInput Wheel #%u", 1 + userid);
             break;
         case XINPUT_DEVSUBTYPE_ARCADE_STICK:
-            SDL_snprintf(name, sizeof(name), "XInput ArcadeStick #%u", 1 + userid);
+            (void)SDL_snprintf(name, sizeof name, "XInput ArcadeStick #%u", 1 + userid);
             break;
         case XINPUT_DEVSUBTYPE_FLIGHT_STICK:
-            SDL_snprintf(name, sizeof(name), "XInput FlightStick #%u", 1 + userid);
+            (void)SDL_snprintf(name, sizeof name, "XInput FlightStick #%u", 1 + userid);
             break;
         case XINPUT_DEVSUBTYPE_DANCE_PAD:
-            SDL_snprintf(name, sizeof(name), "XInput DancePad #%u", 1 + userid);
+            (void)SDL_snprintf(name, sizeof name, "XInput DancePad #%u", 1 + userid);
             break;
         case XINPUT_DEVSUBTYPE_GUITAR:
         case XINPUT_DEVSUBTYPE_GUITAR_ALTERNATE:
         case XINPUT_DEVSUBTYPE_GUITAR_BASS:
-            SDL_snprintf(name, sizeof(name), "XInput Guitar #%u", 1 + userid);
+            (void)SDL_snprintf(name, sizeof name, "XInput Guitar #%u", 1 + userid);
             break;
         case XINPUT_DEVSUBTYPE_DRUM_KIT:
-            SDL_snprintf(name, sizeof(name), "XInput DrumKit #%u", 1 + userid);
+            (void)SDL_snprintf(name, sizeof name, "XInput DrumKit #%u", 1 + userid);
             break;
         case XINPUT_DEVSUBTYPE_ARCADE_PAD:
-            SDL_snprintf(name, sizeof(name), "XInput ArcadePad #%u", 1 + userid);
+            (void)SDL_snprintf(name, sizeof name, "XInput ArcadePad #%u", 1 + userid);
             break;
         default:
-            SDL_snprintf(name, sizeof(name), "XInput Device #%u", 1 + userid);
+            (void)SDL_snprintf(name, sizeof name, "XInput Device #%u", 1 + userid);
             break;
         }
     }
@@ -207,7 +207,7 @@ static void GuessXInputDevice(Uint8 userid, Uint16 *pVID, Uint16 *pPID, Uint16 *
                     /* Steam encodes the real device in the path */
                     int realVID = rdi.hid.dwVendorId;
                     int realPID = rdi.hid.dwProductId;
-                    SDL_sscanf(devName, "\\\\.\\pipe\\HID#VID_045E&PID_028E&IG_00#%x&%x&", &realVID, &realPID);
+                    (void)SDL_sscanf(devName, "\\\\.\\pipe\\HID#VID_045E&PID_028E&IG_00#%x&%x&", &realVID, &realPID);
                     *pVID = (Uint16)realVID;
                     *pPID = (Uint16)realPID;
                     *pVersion = 0;
@@ -279,7 +279,7 @@ static void AddXInputDevice(Uint8 userid, BYTE SubType, JoyStick_DeviceData **pC
         SDL_free(pNewJoystick);
         return; /* better luck next time? */
     }
-    SDL_snprintf(pNewJoystick->path, sizeof(pNewJoystick->path), "XInput#%d", userid);
+    (void)SDL_snprintf(pNewJoystick->path, sizeof pNewJoystick->path, "XInput#%d", userid);
     if (!SDL_XInputUseOldJoystickMapping()) {
         GuessXInputDevice(userid, &vendor, &product, &version);
 
@@ -434,7 +434,7 @@ static void UpdateXInputJoystickState_OLD(SDL_Joystick *joystick, XINPUT_STATE_E
     SDL_PrivateJoystickAxis(joystick, 4, (Sint16)(((int)pXInputState->Gamepad.bLeftTrigger * 65535 / 255) - 32768));
     SDL_PrivateJoystickAxis(joystick, 5, (Sint16)(((int)pXInputState->Gamepad.bRightTrigger * 65535 / 255) - 32768));
 
-    for (button = 0; button < SDL_arraysize(s_XInputButtons); ++button) {
+    for (button = 0; button < (Uint8)SDL_arraysize(s_XInputButtons); ++button) {
         SDL_PrivateJoystickButton(joystick, button, (wButtons & s_XInputButtons[button]) ? SDL_PRESSED : SDL_RELEASED);
     }
 
@@ -460,7 +460,7 @@ static void UpdateXInputJoystickState(SDL_Joystick *joystick, XINPUT_STATE_EX *p
     SDL_PrivateJoystickAxis(joystick, 4, ~pXInputState->Gamepad.sThumbRY);
     SDL_PrivateJoystickAxis(joystick, 5, ((int)pXInputState->Gamepad.bRightTrigger * 257) - 32768);
 
-    for (button = 0; button < SDL_arraysize(s_XInputButtons); ++button) {
+    for (button = 0; button < (Uint8)SDL_arraysize(s_XInputButtons); ++button) {
         SDL_PrivateJoystickButton(joystick, button, (wButtons & s_XInputButtons[button]) ? SDL_PRESSED : SDL_RELEASED);
     }
 

+ 2 - 1
src/locale/macosx/SDL_syslocale.m

@@ -48,7 +48,8 @@ void SDL_SYS_GetPreferredLocales(char *buf, size_t buflen)
             // convert '-' to '_'...
             //  These are always full lang-COUNTRY, so we search from the back,
             //  so things like zh-Hant-CN find the right '-' to convert.
-            if ((ptr = SDL_strrchr(buf, '-')) != NULL) {
+            ptr = SDL_strrchr(buf, '-');
+            if (ptr != NULL) {
                 *ptr = '_';
             }
 

+ 1 - 1
src/locale/windows/SDL_syslocale.c

@@ -49,7 +49,7 @@ static void SDL_SYS_GetPreferredLocales_winxp(char *buf, size_t buflen)
     if (langrc == 0) {
         SDL_SetError("Couldn't obtain language info");
     } else {
-        SDL_snprintf(buf, buflen, "%s%s%s", lang, ctryrc ? "_" : "", ctryrc ? country : "");
+        (void)SDL_snprintf(buf, buflen, "%s%s%s", lang, ctryrc ? "_" : "", ctryrc ? country : "");
     }
 }
 

+ 2 - 2
src/main/windows/SDL_windows_main.c

@@ -64,7 +64,7 @@ static int main_getcmdline(void)
             return OutOfMemory();
         }
         len = (DWORD)SDL_strlen(arg);
-        argv[i] = (char *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len + 1);
+        argv[i] = (char *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (size_t)len + 1);
         if (!argv[i]) {
             return OutOfMemory();
         }
@@ -104,7 +104,7 @@ int console_wmain(int argc, wchar_t *wargv[], wchar_t *wenvp)
 
 /* This is where execution begins [windowed apps] */
 int WINAPI
-WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
+WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw) /* NOLINT(readability-inconsistent-declaration-parameter-name) */
 {
     return main_getcmdline();
 }

+ 0 - 2
src/misc/SDL_url.c

@@ -21,8 +21,6 @@
 
 #include "SDL_sysurl.h"
 
-extern int SDL_SYS_OpenURL(const char *url);
-
 int SDL_OpenURL(const char *url)
 {
     if (url == NULL) {

+ 1 - 1
src/power/linux/SDL_syspower.c

@@ -50,7 +50,7 @@ static int open_power_file(const char *base, const char *node, const char *key)
         return -1; /* oh well. */
     }
 
-    SDL_snprintf(path, pathlen, "%s/%s/%s", base, node, key);
+    (void)SDL_snprintf(path, pathlen, "%s/%s/%s", base, node, key);
     fd = open(path, O_RDONLY | O_CLOEXEC);
     SDL_stack_free(path);
     return fd;

+ 11 - 9
src/render/SDL_render.c

@@ -1340,7 +1340,7 @@ SDL_CreateTexture(SDL_Renderer *renderer, Uint32 format, int access, int w, int
         } else if (access == SDL_TEXTUREACCESS_STREAMING) {
             /* The pitch is 4 byte aligned */
             texture->pitch = (((w * SDL_BYTESPERPIXEL(format)) + 3) & ~3);
-            texture->pixels = SDL_calloc(1, texture->pitch * h);
+            texture->pixels = SDL_calloc(1, (size_t)texture->pitch * h);
             if (!texture->pixels) {
                 SDL_DestroyTexture(texture);
                 return NULL;
@@ -1687,7 +1687,7 @@ static int SDL_UpdateTextureYUV(SDL_Texture *texture, const SDL_Rect *rect,
     } else {
         /* Use a temporary buffer for updating */
         const int temp_pitch = (((rect->w * SDL_BYTESPERPIXEL(native->format)) + 3) & ~3);
-        const size_t alloclen = rect->h * temp_pitch;
+        const size_t alloclen = (size_t)rect->h * temp_pitch;
         if (alloclen > 0) {
             void *temp_pixels = SDL_malloc(alloclen);
             if (temp_pixels == NULL) {
@@ -1727,7 +1727,7 @@ static int SDL_UpdateTextureNative(SDL_Texture *texture, const SDL_Rect *rect,
     } else {
         /* Use a temporary buffer for updating */
         const int temp_pitch = (((rect->w * SDL_BYTESPERPIXEL(native->format)) + 3) & ~3);
-        const size_t alloclen = rect->h * temp_pitch;
+        const size_t alloclen = (size_t)rect->h * temp_pitch;
         if (alloclen > 0) {
             void *temp_pixels = SDL_malloc(alloclen);
             if (temp_pixels == NULL) {
@@ -1821,7 +1821,7 @@ static int SDL_UpdateTextureYUVPlanar(SDL_Texture *texture, const SDL_Rect *rect
     } else {
         /* Use a temporary buffer for updating */
         const int temp_pitch = (((rect->w * SDL_BYTESPERPIXEL(native->format)) + 3) & ~3);
-        const size_t alloclen = rect->h * temp_pitch;
+        const size_t alloclen = (size_t)rect->h * temp_pitch;
         if (alloclen > 0) {
             void *temp_pixels = SDL_malloc(alloclen);
             if (temp_pixels == NULL) {
@@ -1871,7 +1871,7 @@ static int SDL_UpdateTextureNVPlanar(SDL_Texture *texture, const SDL_Rect *rect,
     } else {
         /* Use a temporary buffer for updating */
         const int temp_pitch = (((rect->w * SDL_BYTESPERPIXEL(native->format)) + 3) & ~3);
-        const size_t alloclen = rect->h * temp_pitch;
+        const size_t alloclen = (size_t)rect->h * temp_pitch;
         if (alloclen > 0) {
             void *temp_pixels = SDL_malloc(alloclen);
             if (temp_pixels == NULL) {
@@ -2313,9 +2313,9 @@ static int UpdateLogicalSize(SDL_Renderer *renderer, SDL_bool flush_viewport_cmd
 
     if (renderer->integer_scale) {
         if (want_aspect > real_aspect) {
-            scale = (float)(w / renderer->logical_w);
+            scale = (float)(w) / renderer->logical_w;
         } else {
-            scale = (float)(h / renderer->logical_h);
+            scale = (float)(h) / renderer->logical_h;
         }
 
         if (scale < 1.0f) {
@@ -2452,10 +2452,12 @@ int SDL_RenderSetViewport(SDL_Renderer *renderer, const SDL_Rect *rect)
         if (SDL_GetRendererOutputSize(renderer, &w, &h) < 0) {
             return -1;
         }
-        renderer->viewport.x = (double)0;
-        renderer->viewport.y = (double)0;
+        renderer->viewport.x = 0.0;
+        renderer->viewport.y = 0.0;
+        /* NOLINTBEGIN(clang-analyzer-core.uninitialized.Assign): SDL_GetRendererOutputSize cannot fail */
         renderer->viewport.w = (double)w;
         renderer->viewport.h = (double)h;
+        /* NOLINTEND(clang-analyzer-core.uninitialized.Assign) */
     }
     retval = QueueCmdSetViewport(renderer);
     return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer);

+ 4 - 4
src/render/SDL_yuv_sw.c

@@ -142,7 +142,7 @@ int SDL_SW_UpdateYUVTexture(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect,
         if (rect->x == 0 && rect->y == 0 &&
             rect->w == swdata->w && rect->h == swdata->h) {
             SDL_memcpy(swdata->pixels, pixels,
-                       (swdata->h * swdata->w) + 2 * ((swdata->h + 1) / 2) * ((swdata->w + 1) / 2));
+                       (size_t)(swdata->h * swdata->w) + 2 * ((swdata->h + 1) / 2) * ((swdata->w + 1) / 2));
         } else {
             Uint8 *src, *dst;
             int row;
@@ -194,7 +194,7 @@ int SDL_SW_UpdateYUVTexture(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect,
         dst =
             swdata->planes[0] + rect->y * swdata->pitches[0] +
             rect->x * 2;
-        length = 4 * ((rect->w + 1) / 2);
+        length = 4 * (((size_t)rect->w + 1) / 2);
         for (row = 0; row < rect->h; ++row) {
             SDL_memcpy(dst, src, length);
             src += pitch;
@@ -206,7 +206,7 @@ int SDL_SW_UpdateYUVTexture(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect,
     {
         if (rect->x == 0 && rect->y == 0 && rect->w == swdata->w && rect->h == swdata->h) {
             SDL_memcpy(swdata->pixels, pixels,
-                       (swdata->h * swdata->w) + 2 * ((swdata->h + 1) / 2) * ((swdata->w + 1) / 2));
+                       (size_t)(swdata->h * swdata->w) + 2 * ((swdata->h + 1) / 2) * ((swdata->w + 1) / 2));
         } else {
 
             Uint8 *src, *dst;
@@ -227,7 +227,7 @@ int SDL_SW_UpdateYUVTexture(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect,
             src = (Uint8 *)pixels + rect->h * pitch;
             dst = swdata->pixels + swdata->h * swdata->w;
             dst += 2 * ((rect->y + 1) / 2) * ((swdata->w + 1) / 2) + 2 * (rect->x / 2);
-            length = 2 * ((rect->w + 1) / 2);
+            length = 2 * (((size_t)rect->w + 1) / 2);
             for (row = 0; row < (rect->h + 1) / 2; ++row) {
                 SDL_memcpy(dst, src, length);
                 src += 2 * ((pitch + 1) / 2);

+ 15 - 14
src/render/direct3d/SDL_render_d3d.c

@@ -480,9 +480,9 @@ static int D3D_UpdateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *textur
     }
 
     d3drect.left = x;
-    d3drect.right = x + w;
+    d3drect.right = (LONG)x + w;
     d3drect.top = y;
-    d3drect.bottom = y + h;
+    d3drect.bottom = (LONG)y + h;
 
     result = IDirect3DTexture9_LockRect(texture->staging, 0, &locked, &d3drect, 0);
     if (FAILED(result)) {
@@ -493,7 +493,7 @@ static int D3D_UpdateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *textur
     dst = (Uint8 *)locked.pBits;
     length = w * SDL_BYTESPERPIXEL(texture->format);
     if (length == pitch && length == locked.Pitch) {
-        SDL_memcpy(dst, src, length * h);
+        SDL_memcpy(dst, src, (size_t)length * h);
     } else {
         if (length > pitch) {
             length = pitch;
@@ -676,7 +676,7 @@ static int D3D_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
             }
         }
         *pixels =
-            (void *)((Uint8 *)texturedata->pixels + rect->y * texturedata->pitch +
+            (void *)(texturedata->pixels + rect->y * texturedata->pitch +
                      rect->x * SDL_BYTESPERPIXEL(texture->format));
         *pitch = texturedata->pitch;
     } else
@@ -691,9 +691,9 @@ static int D3D_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
         }
 
         d3drect.left = rect->x;
-        d3drect.right = rect->x + rect->w;
+        d3drect.right = (LONG)rect->x + rect->w;
         d3drect.top = rect->y;
-        d3drect.bottom = rect->y + rect->h;
+        d3drect.bottom = (LONG)rect->y + rect->h;
 
         result = IDirect3DTexture9_LockRect(texturedata->texture.staging, 0, &locked, &d3drect, 0);
         if (FAILED(result)) {
@@ -717,7 +717,7 @@ static void D3D_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
     if (texturedata->yuv) {
         const SDL_Rect *rect = &texturedata->locked_rect;
         void *pixels =
-            (void *)((Uint8 *)texturedata->pixels + rect->y * texturedata->pitch +
+            (void *)(texturedata->pixels + rect->y * texturedata->pitch +
                      rect->x * SDL_BYTESPERPIXEL(texture->format));
         D3D_UpdateTexture(renderer, texture, rect, pixels, texturedata->pitch);
     } else
@@ -1086,10 +1086,10 @@ static int SetDrawState(D3D_RenderData *data, const SDL_RenderCommand *cmd)
         const SDL_Rect *viewport = &data->drawstate.viewport;
         const SDL_Rect *rect = &data->drawstate.cliprect;
         RECT d3drect;
-        d3drect.left = viewport->x + rect->x;
-        d3drect.top = viewport->y + rect->y;
-        d3drect.right = viewport->x + rect->x + rect->w;
-        d3drect.bottom = viewport->y + rect->y + rect->h;
+        d3drect.left = (LONG)viewport->x + rect->x;
+        d3drect.top = (LONG)viewport->y + rect->y;
+        d3drect.right = (LONG)viewport->x + rect->x + rect->w;
+        d3drect.bottom = (LONG)viewport->y + rect->y + rect->h;
         IDirect3DDevice9_SetScissorRect(data->device, &d3drect);
         data->drawstate.cliprect_dirty = SDL_FALSE;
     }
@@ -1239,7 +1239,8 @@ static int D3D_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, v
             const Vertex *verts = (Vertex *)(((Uint8 *)vertices) + first);
 
             /* DirectX 9 has the same line rasterization semantics as GDI,
-               so we need to close the endpoint of the line with a second draw call. */
+               so we need to close the endpoint of the line with a second draw call.
+               NOLINTNEXTLINE(clang-analyzer-core.NullDereference): FIXME: Can verts truly not be NULL ? */
             const SDL_bool close_endpoint = ((count == 2) || (verts[0].x != verts[count - 1].x) || (verts[0].y != verts[count - 1].y));
 
             SetDrawState(data, cmd);
@@ -1326,9 +1327,9 @@ static int D3D_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect,
     }
 
     d3drect.left = rect->x;
-    d3drect.right = rect->x + rect->w;
+    d3drect.right = (LONG)rect->x + rect->w;
     d3drect.top = rect->y;
-    d3drect.bottom = rect->y + rect->h;
+    d3drect.bottom = (LONG)rect->y + rect->h;
 
     result = IDirect3DSurface9_LockRect(surface, &locked, &d3drect, D3DLOCK_READONLY);
     if (FAILED(result)) {

+ 8 - 8
src/render/direct3d11/SDL_render_d3d11.c

@@ -702,9 +702,9 @@ static int D3D11_GetViewportAlignedD3DRect(SDL_Renderer *renderer, const SDL_Rec
     switch (rotation) {
     case DXGI_MODE_ROTATION_IDENTITY:
         outRect->left = sdlRect->x;
-        outRect->right = sdlRect->x + sdlRect->w;
+        outRect->right = (LONG)sdlRect->x + sdlRect->w;
         outRect->top = sdlRect->y;
-        outRect->bottom = sdlRect->y + sdlRect->h;
+        outRect->bottom = (LONG)sdlRect->y + sdlRect->h;
         if (includeViewportOffset) {
             outRect->left += viewport->x;
             outRect->right += viewport->x;
@@ -714,7 +714,7 @@ static int D3D11_GetViewportAlignedD3DRect(SDL_Renderer *renderer, const SDL_Rec
         break;
     case DXGI_MODE_ROTATION_ROTATE270:
         outRect->left = sdlRect->y;
-        outRect->right = sdlRect->y + sdlRect->h;
+        outRect->right = (LONG)sdlRect->y + sdlRect->h;
         outRect->top = viewport->w - sdlRect->x - sdlRect->w;
         outRect->bottom = viewport->w - sdlRect->x;
         break;
@@ -728,7 +728,7 @@ static int D3D11_GetViewportAlignedD3DRect(SDL_Renderer *renderer, const SDL_Rec
         outRect->left = viewport->h - sdlRect->y - sdlRect->h;
         outRect->right = viewport->h - sdlRect->y;
         outRect->top = sdlRect->x;
-        outRect->bottom = sdlRect->x + sdlRect->h;
+        outRect->bottom = (LONG)sdlRect->x + sdlRect->h;
         break;
     default:
         return SDL_SetError("The physical display is in an unknown or unsupported rotation");
@@ -930,7 +930,7 @@ static HRESULT D3D11_CreateWindowSizeDependentResources(SDL_Renderer *renderer)
 #endif
     } else {
         result = D3D11_CreateSwapChain(renderer, w, h);
-        if (FAILED(result)) {
+        if (FAILED(result) || data->swapChain == NULL) {
             goto done;
         }
     }
@@ -1297,7 +1297,7 @@ static int D3D11_UpdateTextureInternal(D3D11_RenderData *rendererData, ID3D11Tex
     dst = textureMemory.pData;
     length = w * bpp;
     if (length == pitch && length == textureMemory.RowPitch) {
-        SDL_memcpy(dst, src, length * h);
+        SDL_memcpy(dst, src, (size_t)length * h);
     } else {
         if (length > (UINT)pitch) {
             length = pitch;
@@ -1448,7 +1448,7 @@ static int D3D11_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
         }
         textureData->locked_rect = *rect;
         *pixels =
-            (void *)((Uint8 *)textureData->pixels + rect->y * textureData->pitch +
+            (void *)(textureData->pixels + rect->y * textureData->pitch +
                      rect->x * SDL_BYTESPERPIXEL(texture->format));
         *pitch = textureData->pitch;
         return 0;
@@ -1519,7 +1519,7 @@ static void D3D11_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
     if (textureData->yuv || textureData->nv12) {
         const SDL_Rect *rect = &textureData->locked_rect;
         void *pixels =
-            (void *)((Uint8 *)textureData->pixels + rect->y * textureData->pitch +
+            (void *)(textureData->pixels + rect->y * textureData->pitch +
                      rect->x * SDL_BYTESPERPIXEL(texture->format));
         D3D11_UpdateTexture(renderer, texture, rect, pixels, textureData->pitch);
         return;

+ 9 - 9
src/render/direct3d12/SDL_render_d3d12.c

@@ -1104,9 +1104,9 @@ static int D3D12_GetViewportAlignedD3DRect(SDL_Renderer *renderer, const SDL_Rec
     switch (rotation) {
     case DXGI_MODE_ROTATION_IDENTITY:
         outRect->left = sdlRect->x;
-        outRect->right = sdlRect->x + sdlRect->w;
+        outRect->right = (LONG)sdlRect->x + sdlRect->w;
         outRect->top = sdlRect->y;
-        outRect->bottom = sdlRect->y + sdlRect->h;
+        outRect->bottom = (LONG)sdlRect->y + sdlRect->h;
         if (includeViewportOffset) {
             outRect->left += viewport->x;
             outRect->right += viewport->x;
@@ -1116,7 +1116,7 @@ static int D3D12_GetViewportAlignedD3DRect(SDL_Renderer *renderer, const SDL_Rec
         break;
     case DXGI_MODE_ROTATION_ROTATE270:
         outRect->left = sdlRect->y;
-        outRect->right = sdlRect->y + sdlRect->h;
+        outRect->right = (LONG)sdlRect->y + sdlRect->h;
         outRect->top = viewport->w - sdlRect->x - sdlRect->w;
         outRect->bottom = viewport->w - sdlRect->x;
         break;
@@ -1130,7 +1130,7 @@ static int D3D12_GetViewportAlignedD3DRect(SDL_Renderer *renderer, const SDL_Rec
         outRect->left = viewport->h - sdlRect->y - sdlRect->h;
         outRect->right = viewport->h - sdlRect->y;
         outRect->top = sdlRect->x;
-        outRect->bottom = sdlRect->x + sdlRect->h;
+        outRect->bottom = (LONG)sdlRect->x + sdlRect->h;
         break;
     default:
         return SDL_SetError("The physical display is in an unknown or unsupported rotation");
@@ -1298,7 +1298,7 @@ static HRESULT D3D12_CreateWindowSizeDependentResources(SDL_Renderer *renderer)
     /* Set the proper rotation for the swap chain. */
     if (WIN_IsWindows8OrGreater()) {
         if (data->swapEffect == DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL) {
-            result = D3D_CALL(data->swapChain, SetRotation, data->rotation);
+            result = D3D_CALL(data->swapChain, SetRotation, data->rotation); /* NOLINT(clang-analyzer-core.NullDereference) */
             if (FAILED(result)) {
                 WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("IDXGISwapChain4::SetRotation"), result);
                 goto done;
@@ -1316,7 +1316,7 @@ static HRESULT D3D12_CreateWindowSizeDependentResources(SDL_Renderer *renderer)
             goto done;
         }
 #else
-        result = D3D_CALL(data->swapChain, GetBuffer,
+        result = D3D_CALL(data->swapChain, GetBuffer, /* NOLINT(clang-analyzer-core.NullDereference) */
                           i,
                           D3D_GUID(SDL_IID_ID3D12Resource),
                           (void **)&data->renderTargets[i]);
@@ -1729,7 +1729,7 @@ static int D3D12_UpdateTextureInternal(D3D12_RenderData *rendererData, ID3D12Res
     dst = textureMemory;
     length = w * bpp;
     if (length == pitch && length == pitchedDesc.RowPitch) {
-        SDL_memcpy(dst, src, length * h);
+        SDL_memcpy(dst, src, (size_t)length * h);
     } else {
         if (length > (UINT)pitch) {
             length = pitch;
@@ -1902,7 +1902,7 @@ static int D3D12_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
         }
         textureData->lockedRect = *rect;
         *pixels =
-            (void *)((Uint8 *)textureData->pixels + rect->y * textureData->pitch +
+            (void *)(textureData->pixels + rect->y * textureData->pitch +
                      rect->x * SDL_BYTESPERPIXEL(texture->format));
         *pitch = textureData->pitch;
         return 0;
@@ -2013,7 +2013,7 @@ static void D3D12_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
     if (textureData->yuv || textureData->nv12) {
         const SDL_Rect *rect = &textureData->lockedRect;
         void *pixels =
-            (void *)((Uint8 *)textureData->pixels + rect->y * textureData->pitch +
+            (void *)(textureData->pixels + rect->y * textureData->pitch +
                      rect->x * SDL_BYTESPERPIXEL(texture->format));
         D3D12_UpdateTexture(renderer, texture, rect, pixels, textureData->pitch);
         return;

+ 1 - 1
src/render/metal/SDL_render_metal.m

@@ -1286,7 +1286,7 @@ SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, const size_t
         [data.mtlcmdencoder setFragmentTexture:texturedata.mtltexture atIndex:0];
 #if SDL_HAVE_YUV
         if (texturedata.yuv || texturedata.nv12) {
-            [data.mtlcmdencoder setFragmentTexture:texturedata.mtltexture_uv atIndex:1];
+            [data.mtlcmdencoder setFragmentTexture:texturedata.mtltextureUv atIndex:1];
             [data.mtlcmdencoder setFragmentBuffer:data.mtlbufconstants offset:texturedata.conversionBufferOffset atIndex:1];
         }
 #endif

+ 4 - 7
src/render/opengl/SDL_render_gl.c

@@ -50,9 +50,6 @@
    http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_texturedata/opengl_texturedata.html
 */
 
-/* Used to re-create the window with OpenGL capability */
-extern int SDL_RecreateWindow(SDL_Window *window, Uint32 flags);
-
 static const float inv255f = 1.0f / 255.0f;
 
 typedef struct GL_FBOList GL_FBOList;
@@ -477,7 +474,7 @@ static int GL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
     if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
         size_t size;
         data->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format);
-        size = texture->h * data->pitch;
+        size = (size_t)texture->h * data->pitch;
         if (texture->format == SDL_PIXELFORMAT_YV12 ||
             texture->format == SDL_PIXELFORMAT_IYUV) {
             /* Need to add size for the U and V planes */
@@ -695,7 +692,7 @@ static int GL_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
     GL_TextureData *data = (GL_TextureData *)texture->driverdata;
     const int texturebpp = SDL_BYTESPERPIXEL(texture->format);
 
-    SDL_assert(texturebpp != 0); /* otherwise, division by zero later. */
+    SDL_assert_release(texturebpp != 0); /* otherwise, division by zero later. */
 
     GL_ActivateRenderer(renderer);
 
@@ -1430,12 +1427,12 @@ static int GL_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect,
                             SDL_GetPixelFormatName(temp_format));
     }
 
-    if (!rect->w || !rect->h) {
+    if (rect->w == 0 || rect->h == 0) {
         return 0; /* nothing to do. */
     }
 
     temp_pitch = rect->w * SDL_BYTESPERPIXEL(temp_format);
-    temp_pixels = SDL_malloc(rect->h * temp_pitch);
+    temp_pixels = SDL_malloc((size_t)rect->h * temp_pitch);
     if (temp_pixels == NULL) {
         return SDL_OutOfMemory();
     }

+ 1 - 1
src/render/opengl/SDL_shaders_gl.c

@@ -472,7 +472,7 @@ static SDL_bool CompileShaderProgram(GL_ShaderContext *ctx, int index, GL_Shader
     ctx->glUseProgramObjectARB(data->program);
     for (i = 0; i < num_tmus_bound; ++i) {
         char tex_name[10];
-        SDL_snprintf(tex_name, SDL_arraysize(tex_name), "tex%d", i);
+        (void)SDL_snprintf(tex_name, SDL_arraysize(tex_name), "tex%d", i);
         location = ctx->glGetUniformLocationARB(data->program, tex_name);
         if (location >= 0) {
             ctx->glUniform1iARB(location, i);

+ 4 - 7
src/render/opengles2/SDL_render_gles2.c

@@ -46,9 +46,6 @@
 #define RENDERER_CONTEXT_MAJOR 2
 #define RENDERER_CONTEXT_MINOR 0
 
-/* Used to re-create the window with OpenGL ES capability */
-extern int SDL_RecreateWindow(SDL_Window *window, Uint32 flags);
-
 /*************************************************************************************************
  * Context structures                                                                            *
  *************************************************************************************************/
@@ -1465,7 +1462,7 @@ static int GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
     if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
         size_t size;
         data->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format);
-        size = texture->h * data->pitch;
+        size = (size_t)texture->h * data->pitch;
 #if SDL_HAVE_YUV
         if (data->yuv) {
             /* Need to add size for the U and V planes */
@@ -1565,7 +1562,7 @@ static int GLES2_TexSubImage2D(GLES2_RenderData *data, GLenum target, GLint xoff
     Uint32 *blob2 = NULL;
 #endif
     Uint8 *src;
-    int src_pitch;
+    size_t src_pitch;
     int y;
 
     if ((width == 0) || (height == 0) || (bpp == 0)) {
@@ -1573,7 +1570,7 @@ static int GLES2_TexSubImage2D(GLES2_RenderData *data, GLenum target, GLint xoff
     }
 
     /* Reformat the texture data into a tightly packed array */
-    src_pitch = width * bpp;
+    src_pitch = (size_t)width * bpp;
     src = (Uint8 *)pixels;
     if (pitch != src_pitch) {
         blob = (Uint8 *)SDL_malloc(src_pitch * height);
@@ -1915,7 +1912,7 @@ static int GLES2_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect,
     int status;
 
     temp_pitch = rect->w * SDL_BYTESPERPIXEL(temp_format);
-    buflen = rect->h * temp_pitch;
+    buflen = (size_t)rect->h * temp_pitch;
     if (buflen == 0) {
         return 0; /* nothing to do. */
     }

+ 4 - 4
src/render/software/SDL_render_sw.c

@@ -142,7 +142,7 @@ static int SW_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
     dst = (Uint8 *)surface->pixels +
           rect->y * surface->pitch +
           rect->x * surface->format->BytesPerPixel;
-    length = rect->w * surface->format->BytesPerPixel;
+    length = (size_t)rect->w * surface->format->BytesPerPixel;
     for (row = 0; row < rect->h; ++row) {
         SDL_memcpy(dst, src, length);
         src += pitch;
@@ -538,9 +538,9 @@ static int SW_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_
     int i;
     int count = indices ? num_indices : num_vertices;
     void *verts;
-    int sz = texture ? sizeof(GeometryCopyData) : sizeof(GeometryFillData);
+    size_t sz = texture != NULL ? sizeof(GeometryCopyData) : sizeof(GeometryFillData);
 
-    verts = (void *)SDL_AllocateRenderVertices(renderer, count * sz, 0, &cmd->data.draw.first);
+    verts = SDL_AllocateRenderVertices(renderer, count * sz, 0, &cmd->data.draw.first);
     if (verts == NULL) {
         return -1;
     }
@@ -641,7 +641,7 @@ static void SetDrawState(SDL_Surface *surface, SW_DrawStateCache *drawstate)
     if (drawstate->surface_cliprect_dirty) {
         const SDL_Rect *viewport = drawstate->viewport;
         const SDL_Rect *cliprect = drawstate->cliprect;
-        SDL_assert(viewport != NULL); /* the higher level should have forced a SDL_RENDERCMD_SETVIEWPORT */
+        SDL_assert_release(viewport != NULL); /* the higher level should have forced a SDL_RENDERCMD_SETVIEWPORT */
 
         if (cliprect != NULL) {
             SDL_Rect clip_rect;

+ 1 - 1
src/render/software/SDL_rotate.c

@@ -432,7 +432,7 @@ static void transformSurfaceY(SDL_Surface *src, SDL_Surface *dst, int isin, int
     /*
      * Clear surface to colorkey
      */
-    SDL_memset(pc, (int)(get_colorkey(src) & 0xff), dst->pitch * dst->h);
+    SDL_memset(pc, (int)(get_colorkey(src) & 0xff), (size_t)dst->pitch * dst->h);
     /*
      * Iterate through destination surface
      */

+ 17 - 10
src/render/software/SDL_triangle.c

@@ -659,7 +659,7 @@ int SDL_SW_BlitTriangle(
         tmp_info.src_pitch = src_pitch;
 
         /* dst */
-        tmp_info.dst = (Uint8 *)dst_ptr;
+        tmp_info.dst = dst_ptr;
         tmp_info.dst_pitch = dst_pitch;
 
         SDL_BlitTriangle_Slow(&tmp_info, s2_x_area, dstrect, area, bias_w0, bias_w1, bias_w2,
@@ -682,7 +682,7 @@ int SDL_SW_BlitTriangle(
         TRIANGLE_BEGIN_LOOP
         {
             TRIANGLE_GET_TEXTCOORD
-            Uint8 *sptr = (Uint8 *)((Uint8 *)src_ptr + srcy * src_pitch);
+            Uint8 *sptr = (Uint8 *)src_ptr + srcy * src_pitch;
             dptr[0] = sptr[3 * srcx];
             dptr[1] = sptr[3 * srcx + 1];
             dptr[2] = sptr[3 * srcx + 2];
@@ -700,7 +700,7 @@ int SDL_SW_BlitTriangle(
         TRIANGLE_BEGIN_LOOP
         {
             TRIANGLE_GET_TEXTCOORD
-            Uint8 *sptr = (Uint8 *)((Uint8 *)src_ptr + srcy * src_pitch);
+            Uint8 *sptr = (Uint8 *)src_ptr + srcy * src_pitch;
             *dptr = sptr[srcx];
         }
         TRIANGLE_END_LOOP
@@ -839,14 +839,17 @@ static void SDL_BlitTriangle_Slow(SDL_BlitInfo *info,
             break;
         case SDL_COPY_ADD:
             dstR = srcR + dstR;
-            if (dstR > 255)
+            if (dstR > 255) {
                 dstR = 255;
+            }
             dstG = srcG + dstG;
-            if (dstG > 255)
+            if (dstG > 255) {
                 dstG = 255;
+            }
             dstB = srcB + dstB;
-            if (dstB > 255)
+            if (dstB > 255) {
                 dstB = 255;
+            }
             break;
         case SDL_COPY_MOD:
             dstR = (srcR * dstR) / 255;
@@ -855,17 +858,21 @@ static void SDL_BlitTriangle_Slow(SDL_BlitInfo *info,
             break;
         case SDL_COPY_MUL:
             dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255;
-            if (dstR > 255)
+            if (dstR > 255) {
                 dstR = 255;
+            }
             dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255;
-            if (dstG > 255)
+            if (dstG > 255) {
                 dstG = 255;
+            }
             dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255;
-            if (dstB > 255)
+            if (dstB > 255) {
                 dstB = 255;
+            }
             dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255;
-            if (dstA > 255)
+            if (dstA > 255) {
                 dstA = 255;
+            }
             break;
         }
         if (FORMAT_HAS_ALPHA(dstfmt_val)) {

+ 4 - 0
src/stdlib/SDL_mslibc.c

@@ -41,23 +41,27 @@ __declspec(selectany) int _fltused = 1;
 /* The optimizer on Visual Studio 2005 and later generates memcpy() and memset() calls.
    Always provide it for the SDL2 DLL, but skip it when building static lib w/ static runtime. */
 #if (_MSC_VER >= 1400) && (!defined(_MT) || defined(DLL_EXPORT))
+/* NOLINTNEXTLINE(readability-redundant-declaration) */
 extern void *memcpy(void *dst, const void *src, size_t len);
 #pragma intrinsic(memcpy)
 
 #if !defined(__clang__)
 #pragma function(memcpy)
 #endif
+/* NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name) */
 void *memcpy(void *dst, const void *src, size_t len)
 {
     return SDL_memcpy(dst, src, len);
 }
 
+/* NOLINTNEXTLINE(readability-redundant-declaration) */
 extern void *memset(void *dst, int c, size_t len);
 #pragma intrinsic(memset)
 
 #if !defined(__clang__)
 #pragma function(memset)
 #endif
+/* NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name) */
 void *memset(void *dst, int c, size_t len)
 {
     return SDL_memset(dst, c, len);

+ 12 - 9
src/stdlib/SDL_string.c

@@ -43,14 +43,15 @@
 
 static unsigned UTF8_TrailingBytes(unsigned char c)
 {
-    if (c >= 0xC0 && c <= 0xDF)
+    if (c >= 0xC0 && c <= 0xDF) {
         return 1;
-    else if (c >= 0xE0 && c <= 0xEF)
+    } else if (c >= 0xE0 && c <= 0xEF) {
         return 2;
-    else if (c >= 0xF0 && c <= 0xF4)
+    } else if (c >= 0xF0 && c <= 0xF4) {
         return 3;
-    else
-        return 0;
+    }
+
+    return 0;
 }
 
 #if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOL) || !defined(HAVE_STRTOUL) || !defined(HAVE_STRTOD)
@@ -443,7 +444,7 @@ int SDL_wcscmp(const wchar_t *str1, const wchar_t *str2)
         ++str1;
         ++str2;
     }
-    return (int)(*str1 - *str2);
+    return *str1 - *str2;
 #endif /* HAVE_WCSCMP */
 }
 
@@ -463,7 +464,7 @@ int SDL_wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen)
     if (!maxlen) {
         return 0;
     }
-    return (int)(*str1 - *str2);
+    return *str1 - *str2;
 
 #endif /* HAVE_WCSNCMP */
 }
@@ -666,7 +667,7 @@ SDL_strrev(char *string)
     char *b = &string[len - 1];
     len /= 2;
     while (len--) {
-        char c = *a;
+        char c = *a; /* NOLINT(clang-analyzer-core.uninitialized.Assign) */
         *a++ = *b;
         *b-- = c;
     }
@@ -1038,7 +1039,7 @@ int SDL_strcmp(const char *str1, const char *str2)
     int result;
 
     while (1) {
-        result = (int)((unsigned char)*str1 - (unsigned char)*str2);
+        result = ((unsigned char)*str1 - (unsigned char)*str2);
         if (result != 0 || (*str1 == '\0' /* && *str2 == '\0'*/)) {
             break;
         }
@@ -1138,6 +1139,7 @@ int SDL_vsscanf(const char *text, const char *fmt, va_list ap)
     return vsscanf(text, fmt, ap);
 }
 #else
+/* NOLINTNEXTLINE(readability-non-const-parameter) */
 int SDL_vsscanf(const char *text, const char *fmt, va_list ap)
 {
     int retval = 0;
@@ -1678,6 +1680,7 @@ SDL_PrintFloat(char *text, size_t maxlen, SDL_FormatInfo *info, double arg)
     return length;
 }
 
+/* NOLINTNEXTLINE(readability-non-const-parameter) */
 int SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, va_list ap)
 {
     size_t length = 0;

+ 3 - 3
src/test/SDL_test_assert.c

@@ -52,7 +52,7 @@ void SDLTest_Assert(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *as
     /* Print assert description into a buffer */
     SDL_memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
     va_start(list, assertDescription);
-    SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, assertDescription, list);
+    (void)SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, assertDescription, list);
     va_end(list);
 
     /* Log, then assert and break on failure */
@@ -70,7 +70,7 @@ int SDLTest_AssertCheck(int assertCondition, SDL_PRINTF_FORMAT_STRING const char
     /* Print assert description into a buffer */
     SDL_memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
     va_start(list, assertDescription);
-    SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, assertDescription, list);
+    (void)SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, assertDescription, list);
     va_end(list);
 
     /* Log pass or fail message */
@@ -96,7 +96,7 @@ void SDLTest_AssertPass(SDL_PRINTF_FORMAT_STRING const char *assertDescription,
     /* Print assert description into a buffer */
     SDL_memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
     va_start(list, assertDescription);
-    SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, assertDescription, list);
+    (void)SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, assertDescription, list);
     va_end(list);
 
     /* Log pass message */

+ 50 - 50
src/test/SDL_test_common.c

@@ -54,7 +54,7 @@ static void SDL_snprintfcat(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL
     va_start(ap, fmt);
     text += length;
     maxlen -= length;
-    SDL_vsnprintf(text, maxlen, fmt, ap);
+    (void)SDL_vsnprintf(text, maxlen, fmt, ap);
     va_end(ap);
 }
 
@@ -957,28 +957,28 @@ static void SDLTest_PrintRenderer(SDL_RendererInfo *info)
 
     SDL_Log("  Renderer %s:\n", info->name);
 
-    SDL_snprintf(text, sizeof(text), "    Flags: 0x%8.8" SDL_PRIX32, info->flags);
-    SDL_snprintfcat(text, sizeof(text), " (");
+    (void)SDL_snprintf(text, sizeof text, "    Flags: 0x%8.8" SDL_PRIX32, info->flags);
+    SDL_snprintfcat(text, sizeof text, " (");
     count = 0;
-    for (i = 0; i < sizeof(info->flags) * 8; ++i) {
+    for (i = 0; i < 8 * sizeof info->flags; ++i) {
         Uint32 flag = (1 << i);
         if (info->flags & flag) {
             if (count > 0) {
-                SDL_snprintfcat(text, sizeof(text), " | ");
+                SDL_snprintfcat(text, sizeof text, " | ");
             }
-            SDLTest_PrintRendererFlag(text, sizeof(text), flag);
+            SDLTest_PrintRendererFlag(text, sizeof text, flag);
             ++count;
         }
     }
-    SDL_snprintfcat(text, sizeof(text), ")");
+    SDL_snprintfcat(text, sizeof text, ")");
     SDL_Log("%s\n", text);
 
-    SDL_snprintf(text, sizeof(text), "    Texture formats (%" SDL_PRIu32 "): ", info->num_texture_formats);
+    (void)SDL_snprintf(text, sizeof text, "    Texture formats (%" SDL_PRIu32 "): ", info->num_texture_formats);
     for (i = 0; i < (int)info->num_texture_formats; ++i) {
         if (i > 0) {
-            SDL_snprintfcat(text, sizeof(text), ", ");
+            SDL_snprintfcat(text, sizeof text, ", ");
         }
-        SDLTest_PrintPixelFormat(text, sizeof(text), info->texture_formats[i]);
+        SDLTest_PrintPixelFormat(text, sizeof text, info->texture_formats[i]);
     }
     SDL_Log("%s\n", text);
 
@@ -1065,12 +1065,12 @@ SDLTest_CommonInit(SDLTest_CommonState *state)
             if (n == 0) {
                 SDL_Log("No built-in video drivers\n");
             } else {
-                SDL_snprintf(text, sizeof(text), "Built-in video drivers:");
+                (void)SDL_snprintf(text, sizeof text, "Built-in video drivers:");
                 for (i = 0; i < n; ++i) {
                     if (i > 0) {
-                        SDL_snprintfcat(text, sizeof(text), ",");
+                        SDL_snprintfcat(text, sizeof text, ",");
                     }
-                    SDL_snprintfcat(text, sizeof(text), " %s", SDL_GetVideoDriver(i));
+                    SDL_snprintfcat(text, sizeof text, " %s", SDL_GetVideoDriver(i));
                 }
                 SDL_Log("%s\n", text);
             }
@@ -1262,8 +1262,8 @@ SDLTest_CommonInit(SDLTest_CommonState *state)
             }
 
             if (state->num_windows > 1) {
-                SDL_snprintf(title, SDL_arraysize(title), "%s %d",
-                             state->window_title, i + 1);
+                (void)SDL_snprintf(title, SDL_arraysize(title), "%s %d",
+                                   state->window_title, i + 1);
             } else {
                 SDL_strlcpy(title, state->window_title, SDL_arraysize(title));
             }
@@ -1360,12 +1360,12 @@ SDLTest_CommonInit(SDLTest_CommonState *state)
             if (n == 0) {
                 SDL_Log("No built-in audio drivers\n");
             } else {
-                SDL_snprintf(text, sizeof(text), "Built-in audio drivers:");
+                (void)SDL_snprintf(text, sizeof text, "Built-in audio drivers:");
                 for (i = 0; i < n; ++i) {
                     if (i > 0) {
-                        SDL_snprintfcat(text, sizeof(text), ",");
+                        SDL_snprintfcat(text, sizeof text, ",");
                     }
-                    SDL_snprintfcat(text, sizeof(text), " %s", SDL_GetAudioDriver(i));
+                    SDL_snprintfcat(text, sizeof text, " %s", SDL_GetAudioDriver(i));
                 }
                 SDL_Log("%s\n", text);
             }
@@ -2161,8 +2161,8 @@ void SDLTest_CommonEvent(SDLTest_CommonState *state, SDL_Event *event, int *done
             char message[256];
             SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
 
-            SDL_snprintf(message, sizeof(message), "(%" SDL_PRIs32 ", %" SDL_PRIs32 "), rel (%" SDL_PRIs32 ", %" SDL_PRIs32 ")\n",
-                         lastEvent.x, lastEvent.y, lastEvent.xrel, lastEvent.yrel);
+            (void)SDL_snprintf(message, sizeof message, "(%" SDL_PRIs32 ", %" SDL_PRIs32 "), rel (%" SDL_PRIs32 ", %" SDL_PRIs32 ")\n",
+                               lastEvent.x, lastEvent.y, lastEvent.xrel, lastEvent.yrel);
             SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Last mouse position", message, window);
             break;
         }
@@ -2246,7 +2246,7 @@ void SDLTest_CommonDrawWindowInfo(SDL_Renderer *renderer, SDL_Window *window, in
 
     SDL_SetRenderDrawColor(renderer, 170, 170, 170, 255);
 
-    SDL_snprintf(text, sizeof(text), "SDL_GetCurrentVideoDriver: %s", SDL_GetCurrentVideoDriver());
+    (void)SDL_snprintf(text, sizeof text, "SDL_GetCurrentVideoDriver: %s", SDL_GetCurrentVideoDriver());
     SDLTest_DrawString(renderer, 0, textY, text);
     textY += lineHeight;
 
@@ -2259,31 +2259,31 @@ void SDLTest_CommonDrawWindowInfo(SDL_Renderer *renderer, SDL_Window *window, in
     SDL_SetRenderDrawColor(renderer, 170, 170, 170, 255);
 
     if (0 == SDL_GetRendererInfo(renderer, &info)) {
-        SDL_snprintf(text, sizeof(text), "SDL_GetRendererInfo: name: %s", info.name);
+        (void)SDL_snprintf(text, sizeof text, "SDL_GetRendererInfo: name: %s", info.name);
         SDLTest_DrawString(renderer, 0, textY, text);
         textY += lineHeight;
     }
 
     if (0 == SDL_GetRendererOutputSize(renderer, &w, &h)) {
-        SDL_snprintf(text, sizeof(text), "SDL_GetRendererOutputSize: %dx%d", w, h);
+        (void)SDL_snprintf(text, sizeof text, "SDL_GetRendererOutputSize: %dx%d", w, h);
         SDLTest_DrawString(renderer, 0, textY, text);
         textY += lineHeight;
     }
 
     SDL_RenderGetViewport(renderer, &rect);
-    SDL_snprintf(text, sizeof(text), "SDL_RenderGetViewport: %d,%d, %dx%d",
-                 rect.x, rect.y, rect.w, rect.h);
+    (void)SDL_snprintf(text, sizeof text, "SDL_RenderGetViewport: %d,%d, %dx%d",
+                       rect.x, rect.y, rect.w, rect.h);
     SDLTest_DrawString(renderer, 0, textY, text);
     textY += lineHeight;
 
     SDL_RenderGetScale(renderer, &scaleX, &scaleY);
-    SDL_snprintf(text, sizeof(text), "SDL_RenderGetScale: %f,%f",
-                 scaleX, scaleY);
+    (void)SDL_snprintf(text, sizeof text, "SDL_RenderGetScale: %f,%f",
+                       scaleX, scaleY);
     SDLTest_DrawString(renderer, 0, textY, text);
     textY += lineHeight;
 
     SDL_RenderGetLogicalSize(renderer, &w, &h);
-    SDL_snprintf(text, sizeof(text), "SDL_RenderGetLogicalSize: %dx%d", w, h);
+    (void)SDL_snprintf(text, sizeof text, "SDL_RenderGetLogicalSize: %dx%d", w, h);
     SDLTest_DrawString(renderer, 0, textY, text);
     textY += lineHeight;
 
@@ -2296,23 +2296,23 @@ void SDLTest_CommonDrawWindowInfo(SDL_Renderer *renderer, SDL_Window *window, in
     SDL_SetRenderDrawColor(renderer, 170, 170, 170, 255);
 
     SDL_GetWindowPosition(window, &x, &y);
-    SDL_snprintf(text, sizeof(text), "SDL_GetWindowPosition: %d,%d", x, y);
+    (void)SDL_snprintf(text, sizeof text, "SDL_GetWindowPosition: %d,%d", x, y);
     SDLTest_DrawString(renderer, 0, textY, text);
     textY += lineHeight;
 
     SDL_GetWindowSize(window, &w, &h);
-    SDL_snprintf(text, sizeof(text), "SDL_GetWindowSize: %dx%d", w, h);
+    (void)SDL_snprintf(text, sizeof text, "SDL_GetWindowSize: %dx%d", w, h);
     SDLTest_DrawString(renderer, 0, textY, text);
     textY += lineHeight;
 
-    SDL_snprintf(text, sizeof(text), "SDL_GetWindowFlags: ");
-    SDLTest_PrintWindowFlags(text, sizeof(text), SDL_GetWindowFlags(window));
+    (void)SDL_snprintf(text, sizeof text, "SDL_GetWindowFlags: ");
+    SDLTest_PrintWindowFlags(text, sizeof text, SDL_GetWindowFlags(window));
     SDLTest_DrawString(renderer, 0, textY, text);
     textY += lineHeight;
 
     if (0 == SDL_GetWindowDisplayMode(window, &mode)) {
-        SDL_snprintf(text, sizeof(text), "SDL_GetWindowDisplayMode: %dx%d@%dHz (%s)",
-                     mode.w, mode.h, mode.refresh_rate, SDL_GetPixelFormatName(mode.format));
+        (void)SDL_snprintf(text, sizeof text, "SDL_GetWindowDisplayMode: %dx%d@%dHz (%s)",
+                           mode.w, mode.h, mode.refresh_rate, SDL_GetPixelFormatName(mode.format));
         SDLTest_DrawString(renderer, 0, textY, text);
         textY += lineHeight;
     }
@@ -2325,44 +2325,44 @@ void SDLTest_CommonDrawWindowInfo(SDL_Renderer *renderer, SDL_Window *window, in
 
     SDL_SetRenderDrawColor(renderer, 170, 170, 170, 255);
 
-    SDL_snprintf(text, sizeof(text), "SDL_GetWindowDisplayIndex: %d", windowDisplayIndex);
+    (void)SDL_snprintf(text, sizeof text, "SDL_GetWindowDisplayIndex: %d", windowDisplayIndex);
     SDLTest_DrawString(renderer, 0, textY, text);
     textY += lineHeight;
 
-    SDL_snprintf(text, sizeof(text), "SDL_GetDisplayName: %s", SDL_GetDisplayName(windowDisplayIndex));
+    (void)SDL_snprintf(text, sizeof text, "SDL_GetDisplayName: %s", SDL_GetDisplayName(windowDisplayIndex));
     SDLTest_DrawString(renderer, 0, textY, text);
     textY += lineHeight;
 
     if (0 == SDL_GetDisplayBounds(windowDisplayIndex, &rect)) {
-        SDL_snprintf(text, sizeof(text), "SDL_GetDisplayBounds: %d,%d, %dx%d",
-                     rect.x, rect.y, rect.w, rect.h);
+        (void)SDL_snprintf(text, sizeof text, "SDL_GetDisplayBounds: %d,%d, %dx%d",
+                           rect.x, rect.y, rect.w, rect.h);
         SDLTest_DrawString(renderer, 0, textY, text);
         textY += lineHeight;
     }
 
     if (0 == SDL_GetCurrentDisplayMode(windowDisplayIndex, &mode)) {
-        SDL_snprintf(text, sizeof(text), "SDL_GetCurrentDisplayMode: %dx%d@%d",
-                     mode.w, mode.h, mode.refresh_rate);
+        (void)SDL_snprintf(text, sizeof text, "SDL_GetCurrentDisplayMode: %dx%d@%d",
+                           mode.w, mode.h, mode.refresh_rate);
         SDLTest_DrawString(renderer, 0, textY, text);
         textY += lineHeight;
     }
 
     if (0 == SDL_GetDesktopDisplayMode(windowDisplayIndex, &mode)) {
-        SDL_snprintf(text, sizeof(text), "SDL_GetDesktopDisplayMode: %dx%d@%d",
-                     mode.w, mode.h, mode.refresh_rate);
+        (void)SDL_snprintf(text, sizeof text, "SDL_GetDesktopDisplayMode: %dx%d@%d",
+                           mode.w, mode.h, mode.refresh_rate);
         SDLTest_DrawString(renderer, 0, textY, text);
         textY += lineHeight;
     }
 
     if (0 == SDL_GetDisplayDPI(windowDisplayIndex, &ddpi, &hdpi, &vdpi)) {
-        SDL_snprintf(text, sizeof(text), "SDL_GetDisplayDPI: ddpi: %f, hdpi: %f, vdpi: %f",
-                     ddpi, hdpi, vdpi);
+        (void)SDL_snprintf(text, sizeof text, "SDL_GetDisplayDPI: ddpi: %f, hdpi: %f, vdpi: %f",
+                           ddpi, hdpi, vdpi);
         SDLTest_DrawString(renderer, 0, textY, text);
         textY += lineHeight;
     }
 
-    SDL_snprintf(text, sizeof(text), "SDL_GetDisplayOrientation: ");
-    SDLTest_PrintDisplayOrientation(text, sizeof(text), SDL_GetDisplayOrientation(windowDisplayIndex));
+    (void)SDL_snprintf(text, sizeof text, "SDL_GetDisplayOrientation: ");
+    SDLTest_PrintDisplayOrientation(text, sizeof text, SDL_GetDisplayOrientation(windowDisplayIndex));
     SDLTest_DrawString(renderer, 0, textY, text);
     textY += lineHeight;
 
@@ -2375,14 +2375,14 @@ void SDLTest_CommonDrawWindowInfo(SDL_Renderer *renderer, SDL_Window *window, in
     SDL_SetRenderDrawColor(renderer, 170, 170, 170, 255);
 
     flags = SDL_GetMouseState(&x, &y);
-    SDL_snprintf(text, sizeof(text), "SDL_GetMouseState: %d,%d ", x, y);
-    SDLTest_PrintButtonMask(text, sizeof(text), flags);
+    (void)SDL_snprintf(text, sizeof text, "SDL_GetMouseState: %d,%d ", x, y);
+    SDLTest_PrintButtonMask(text, sizeof text, flags);
     SDLTest_DrawString(renderer, 0, textY, text);
     textY += lineHeight;
 
     flags = SDL_GetGlobalMouseState(&x, &y);
-    SDL_snprintf(text, sizeof(text), "SDL_GetGlobalMouseState: %d,%d ", x, y);
-    SDLTest_PrintButtonMask(text, sizeof(text), flags);
+    (void)SDL_snprintf(text, sizeof text, "SDL_GetGlobalMouseState: %d,%d ", x, y);
+    SDLTest_PrintButtonMask(text, sizeof text, flags);
     SDLTest_DrawString(renderer, 0, textY, text);
     textY += lineHeight;
 

+ 6 - 4
src/test/SDL_test_compare.c

@@ -31,6 +31,8 @@
 
 #include "SDL_test.h"
 
+#define FILENAME_SIZE 128
+
 /* Counter for _CompareSurface calls; used for filename creation when comparisons fail */
 static int _CompareSurfaceCount = 0;
 
@@ -45,8 +47,8 @@ int SDLTest_CompareSurfaces(SDL_Surface *surface, SDL_Surface *referenceSurface,
     int sampleErrorX = 0, sampleErrorY = 0, sampleDist = 0;
     Uint8 R, G, B, A;
     Uint8 Rd, Gd, Bd, Ad;
-    char imageFilename[128];
-    char referenceFilename[128];
+    char imageFilename[FILENAME_SIZE];
+    char referenceFilename[FILENAME_SIZE];
 
     /* Validate input surfaces */
     if (surface == NULL || referenceSurface == NULL) {
@@ -103,9 +105,9 @@ int SDLTest_CompareSurfaces(SDL_Surface *surface, SDL_Surface *referenceSurface,
     if (ret != 0) {
         SDLTest_LogError("Comparison of pixels with allowable error of %i failed %i times.", allowable_error, ret);
         SDLTest_LogError("First detected occurrence at position %i,%i with a squared RGB-difference of %i.", sampleErrorX, sampleErrorY, sampleDist);
-        SDL_snprintf(imageFilename, 127, "CompareSurfaces%04d_TestOutput.bmp", _CompareSurfaceCount);
+        (void)SDL_snprintf(imageFilename, FILENAME_SIZE - 1, "CompareSurfaces%04d_TestOutput.bmp", _CompareSurfaceCount);
         SDL_SaveBMP(surface, imageFilename);
-        SDL_snprintf(referenceFilename, 127, "CompareSurfaces%04d_Reference.bmp", _CompareSurfaceCount);
+        (void)SDL_snprintf(referenceFilename, FILENAME_SIZE - 1, "CompareSurfaces%04d_Reference.bmp", _CompareSurfaceCount);
         SDL_SaveBMP(referenceSurface, referenceFilename);
         SDLTest_LogError("Surfaces from failed comparison saved as '%s' and '%s'", imageFilename, referenceFilename);
     }

+ 1 - 1
src/test/SDL_test_font.c

@@ -3393,7 +3393,7 @@ void SDLTest_TextWindowAddText(SDLTest_TextWindow *textwin, const char *fmt, ...
     va_list ap;
 
     va_start(ap, fmt);
-    SDL_vsnprintf(text, sizeof(text), fmt, ap);
+    (void)SDL_vsnprintf(text, sizeof text, fmt, ap);
     va_end(ap);
 
     SDLTest_TextWindowAddTextWithLength(textwin, text, SDL_strlen(text));

+ 3 - 3
src/test/SDL_test_harness.c

@@ -130,8 +130,8 @@ static Uint64 SDLTest_GenerateExecKey(const char *runSeed, const char *suiteName
     }
 
     /* Convert iteration number into a string */
-    SDL_memset(iterationString, 0, sizeof(iterationString));
-    SDL_snprintf(iterationString, sizeof(iterationString) - 1, "%d", iteration);
+    SDL_memset(iterationString, 0, sizeof iterationString);
+    (void)SDL_snprintf(iterationString, sizeof iterationString - 1, "%d", iteration);
 
     /* Combine the parameters into single string */
     runSeedLength = SDL_strlen(runSeed);
@@ -145,7 +145,7 @@ static Uint64 SDLTest_GenerateExecKey(const char *runSeed, const char *suiteName
         SDL_Error(SDL_ENOMEM);
         return 0;
     }
-    SDL_snprintf(buffer, entireStringLength, "%s%s%s%d", runSeed, suiteName, testName, iteration);
+    (void)SDL_snprintf(buffer, entireStringLength, "%s%s%s%d", runSeed, suiteName, testName, iteration);
 
     /* Hash string and use half of the digest as 64bit exec key */
     SDLTest_Md5Init(&md5Context);

+ 9 - 4
src/test/SDL_test_log.c

@@ -65,16 +65,21 @@ strftime_gcc2_workaround(char *s, size_t max, const char *fmt, const struct tm *
  *
  * \return Ascii representation of the timestamp in localtime in the format '08/23/01 14:55:02'
  */
-static char *SDLTest_TimestampToString(const time_t timestamp)
+static const char *
+SDLTest_TimestampToString(const time_t timestamp)
 {
     time_t copy;
     static char buffer[64];
     struct tm *local;
+    size_t result = 0;
 
     SDL_memset(buffer, 0, sizeof(buffer));
     copy = timestamp;
     local = localtime(&copy);
-    strftime(buffer, sizeof(buffer), "%x %X", local);
+    result = strftime(buffer, sizeof buffer, "%x %X", local);
+    if (result == 0) {
+        return "";
+    }
 
     return buffer;
 }
@@ -90,7 +95,7 @@ void SDLTest_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
     /* Print log message into a buffer */
     SDL_memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
     va_start(list, fmt);
-    SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, fmt, list);
+    (void)SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, fmt, list);
     va_end(list);
 
     /* Log with timestamp and newline */
@@ -108,7 +113,7 @@ void SDLTest_LogError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
     /* Print log message into a buffer */
     SDL_memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
     va_start(list, fmt);
-    SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, fmt, list);
+    (void)SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, fmt, list);
     va_end(list);
 
     /* Log with timestamp and newline */

+ 5 - 5
src/test/SDL_test_memory.c

@@ -242,30 +242,30 @@ void SDLTest_LogAllocations()
     message = tmp;                                         \
     SDL_strlcat(message, line, message_size)
 
-    SDL_strlcpy(line, "Memory allocations:\n", sizeof(line));
+    SDL_strlcpy(line, "Memory allocations:\n", sizeof line);
     ADD_LINE();
-    SDL_strlcpy(line, "Expect 2 allocations from within SDL_GetErrBuf()\n", sizeof(line));
+    SDL_strlcpy(line, "Expect 2 allocations from within SDL_GetErrBuf()\n", sizeof line);
     ADD_LINE();
 
     count = 0;
     total_allocated = 0;
     for (index = 0; index < SDL_arraysize(s_tracked_allocations); ++index) {
         for (entry = s_tracked_allocations[index]; entry; entry = entry->next) {
-            SDL_snprintf(line, sizeof(line), "Allocation %d: %d bytes\n", count, (int)entry->size);
+            (void)SDL_snprintf(line, sizeof line, "Allocation %d: %d bytes\n", count, (int)entry->size);
             ADD_LINE();
             /* Start at stack index 1 to skip our tracking functions */
             for (stack_index = 1; stack_index < SDL_arraysize(entry->stack); ++stack_index) {
                 if (!entry->stack[stack_index]) {
                     break;
                 }
-                SDL_snprintf(line, sizeof(line), "\t0x%" SDL_PRIx64 ": %s\n", entry->stack[stack_index], entry->stack_names[stack_index]);
+                (void)SDL_snprintf(line, sizeof line, "\t0x%" SDL_PRIx64 ": %s\n", entry->stack[stack_index], entry->stack_names[stack_index]);
                 ADD_LINE();
             }
             total_allocated += entry->size;
             ++count;
         }
     }
-    SDL_snprintf(line, sizeof(line), "Total: %.2f Kb in %d allocations\n", (float)total_allocated / 1024, count);
+    (void)SDL_snprintf(line, sizeof line, "Total: %.2f Kb in %d allocations\n", total_allocated / 1024.0, count);
     ADD_LINE();
 #undef ADD_LINE
 

+ 5 - 5
src/thread/SDL_thread.c

@@ -154,7 +154,7 @@ SDL_Generic_GetTLSData(void)
     return storage;
 }
 
-int SDL_Generic_SetTLSData(SDL_TLSData *storage)
+int SDL_Generic_SetTLSData(SDL_TLSData *data)
 {
     SDL_threadID thread = SDL_ThreadID();
     SDL_TLSEntry *prev, *entry;
@@ -164,10 +164,10 @@ int SDL_Generic_SetTLSData(SDL_TLSData *storage)
     prev = NULL;
     for (entry = SDL_generic_TLS; entry; entry = entry->next) {
         if (entry->thread == thread) {
-            if (storage) {
-                entry->storage = storage;
+            if (data != NULL) {
+                entry->storage = data;
             } else {
-                if (prev) {
+                if (prev != NULL) {
                     prev->next = entry->next;
                 } else {
                     SDL_generic_TLS = entry->next;
@@ -182,7 +182,7 @@ int SDL_Generic_SetTLSData(SDL_TLSData *storage)
         entry = (SDL_TLSEntry *)SDL_malloc(sizeof(*entry));
         if (entry) {
             entry->thread = thread;
-            entry->storage = storage;
+            entry->storage = data;
             entry->next = SDL_generic_TLS;
             SDL_generic_TLS = entry;
         }

+ 1 - 1
src/thread/pthread/SDL_syscond.c

@@ -113,7 +113,7 @@ int SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms)
     gettimeofday(&delta, NULL);
 
     abstime.tv_sec = delta.tv_sec + (ms / 1000);
-    abstime.tv_nsec = (delta.tv_usec + (ms % 1000) * 1000) * 1000;
+    abstime.tv_nsec = (long)(delta.tv_usec + (ms % 1000) * 1000) * 1000;
 #endif
     if (abstime.tv_nsec > 1000000000) {
         abstime.tv_sec += 1;

+ 37 - 23
src/video/SDL_RLEaccel.c

@@ -705,10 +705,11 @@ static void RLEAlphaClipBlit(int w, Uint8 *srcbuf, SDL_Surface *surf_dst,
 
     switch (df->BytesPerPixel) {
     case 2:
-        if (df->Gmask == 0x07e0 || df->Rmask == 0x07e0 || df->Bmask == 0x07e0)
+        if (df->Gmask == 0x07e0 || df->Rmask == 0x07e0 || df->Bmask == 0x07e0) {
             RLEALPHACLIPBLIT(Uint16, Uint8, BLIT_TRANSL_565);
-        else
+        } else {
             RLEALPHACLIPBLIT(Uint16, Uint8, BLIT_TRANSL_555);
+        }
         break;
     case 4:
         RLEALPHACLIPBLIT(Uint32, Uint16, BLIT_TRANSL_888);
@@ -755,8 +756,9 @@ static int SDLCALL SDL_RLEAlphaBlit(SDL_Surface *surf_src, SDL_Rect *srcrect,
                         if (run) {
                             srcbuf += 2 * run;
                             ofs += run;
-                        } else if (!ofs)
+                        } else if (ofs == 0) {
                             goto done;
+                        }
                     } while (ofs < w);
 
                     /* skip padding */
@@ -785,8 +787,9 @@ static int SDLCALL SDL_RLEAlphaBlit(SDL_Surface *surf_src, SDL_Rect *srcrect,
                         if (run) {
                             srcbuf += 4 * run;
                             ofs += run;
-                        } else if (!ofs)
+                        } else if (ofs == 0) {
                             goto done;
+                        }
                     } while (ofs < w);
                 } while (--vskip);
             }
@@ -850,10 +853,11 @@ static int SDLCALL SDL_RLEAlphaBlit(SDL_Surface *surf_src, SDL_Rect *srcrect,
 
         switch (df->BytesPerPixel) {
         case 2:
-            if (df->Gmask == 0x07e0 || df->Rmask == 0x07e0 || df->Bmask == 0x07e0)
+            if (df->Gmask == 0x07e0 || df->Rmask == 0x07e0 || df->Bmask == 0x07e0) {
                 RLEALPHABLIT(Uint16, Uint8, BLIT_TRANSL_565);
-            else
+            } else {
                 RLEALPHABLIT(Uint16, Uint8, BLIT_TRANSL_555);
+            }
             break;
         case 4:
             RLEALPHABLIT(Uint32, Uint16, BLIT_TRANSL_888);
@@ -1039,15 +1043,17 @@ static int RLEAlphaSurface(SDL_Surface *surface)
             if (df->Gmask == 0x07e0 || df->Rmask == 0x07e0 || df->Bmask == 0x07e0) {
                 copy_opaque = copy_opaque_16;
                 copy_transl = copy_transl_565;
-            } else
+            } else {
                 return -1;
+            }
             break;
         case 0x7fff:
             if (df->Gmask == 0x03e0 || df->Rmask == 0x03e0 || df->Bmask == 0x03e0) {
                 copy_opaque = copy_opaque_16;
                 copy_transl = copy_transl_555;
-            } else
+            } else {
                 return -1;
+            }
             break;
         default:
             return -1;
@@ -1059,8 +1065,9 @@ static int RLEAlphaSurface(SDL_Surface *surface)
         maxsize = surface->h * (2 + (4 + 2) * (surface->w + 1)) + 2;
         break;
     case 4:
-        if (masksum != 0x00ffffff)
+        if (masksum != 0x00ffffff) {
             return -1; /* requires unused high byte */
+        }
         copy_opaque = copy_32;
         copy_transl = copy_32;
         max_opaque_run = 255; /* runs stored as short ints */
@@ -1128,11 +1135,13 @@ static int RLEAlphaSurface(SDL_Surface *surface)
             do {
                 int run, skip, len;
                 skipstart = x;
-                while (x < w && !ISOPAQUE(src[x], sf))
+                while (x < w && !ISOPAQUE(src[x], sf)) {
                     x++;
+                }
                 runstart = x;
-                while (x < w && ISOPAQUE(src[x], sf))
+                while (x < w && ISOPAQUE(src[x], sf)) {
                     x++;
+                }
                 skip = runstart - skipstart;
                 if (skip == w) {
                     blankline = 1;
@@ -1164,11 +1173,13 @@ static int RLEAlphaSurface(SDL_Surface *surface)
             do {
                 int run, skip, len;
                 skipstart = x;
-                while (x < w && !ISTRANSL(src[x], sf))
+                while (x < w && !ISTRANSL(src[x], sf)) {
                     x++;
+                }
                 runstart = x;
-                while (x < w && ISTRANSL(src[x], sf))
+                while (x < w && ISTRANSL(src[x], sf)) {
                     x++;
+                }
                 skip = runstart - skipstart;
                 blankline &= (skip == w);
                 run = x - runstart;
@@ -1319,16 +1330,19 @@ static int RLEColorkeySurface(SDL_Surface *surface)
         int x = 0;
         int blankline = 0;
         do {
-            int run, skip, len;
+            int run, skip;
+            int len;
             int runstart;
             int skipstart = x;
 
             /* find run of transparent, then opaque pixels */
-            while (x < w && (getpix(srcbuf + x * bpp) & rgbmask) == ckey)
+            while (x < w && (getpix(srcbuf + x * bpp) & rgbmask) == ckey) {
                 x++;
+            }
             runstart = x;
-            while (x < w && (getpix(srcbuf + x * bpp) & rgbmask) != ckey)
+            while (x < w && (getpix(srcbuf + x * bpp) & rgbmask) != ckey) {
                 x++;
+            }
             skip = runstart - skipstart;
             if (skip == w) {
                 blankline = 1;
@@ -1342,14 +1356,14 @@ static int RLEColorkeySurface(SDL_Surface *surface)
             }
             len = SDL_min(run, maxn);
             ADD_COUNTS(skip, len);
-            SDL_memcpy(dst, srcbuf + runstart * bpp, len * bpp);
+            SDL_memcpy(dst, srcbuf + runstart * bpp, (size_t)len * bpp);
             dst += len * bpp;
             run -= len;
             runstart += len;
             while (run) {
                 len = SDL_min(run, maxn);
                 ADD_COUNTS(0, len);
-                SDL_memcpy(dst, srcbuf + runstart * bpp, len * bpp);
+                SDL_memcpy(dst, srcbuf + runstart * bpp, (size_t)len * bpp);
                 dst += len * bpp;
                 runstart += len;
                 run -= len;
@@ -1477,13 +1491,13 @@ static SDL_bool UnRLEAlpha(SDL_Surface *surface)
         uncopy_opaque = uncopy_transl = uncopy_32;
     }
 
-    surface->pixels = SDL_SIMDAlloc(surface->h * surface->pitch);
-    if (!surface->pixels) {
+    surface->pixels = SDL_SIMDAlloc((size_t)surface->h * surface->pitch);
+    if (surface->pixels == NULL) {
         return SDL_FALSE;
     }
     surface->flags |= SDL_SIMD_ALIGNED;
     /* fill background with transparent pixels */
-    SDL_memset(surface->pixels, 0, surface->h * surface->pitch);
+    SDL_memset(surface->pixels, 0, (size_t)surface->h * surface->pitch);
 
     dst = surface->pixels;
     srcbuf = (Uint8 *)(df + 1);
@@ -1543,8 +1557,8 @@ void SDL_UnRLESurface(SDL_Surface *surface, int recode)
                 SDL_Rect full;
 
                 /* re-create the original surface */
-                surface->pixels = SDL_SIMDAlloc(surface->h * surface->pitch);
-                if (!surface->pixels) {
+                surface->pixels = SDL_SIMDAlloc((size_t)surface->h * surface->pitch);
+                if (surface->pixels == NULL) {
                     /* Oh crap... */
                     surface->flags |= SDL_RLEACCEL;
                     return;

+ 1 - 1
src/video/SDL_blit.c

@@ -137,7 +137,7 @@ static SDL_BlitFunc SDL_ChooseBlitFunc(Uint32 src_format, Uint32 dst_format, int
 
         /* Allow an override for testing .. */
         if (override) {
-            SDL_sscanf(override, "%u", &features);
+            (void)SDL_sscanf(override, "%u", &features);
         } else {
             if (SDL_HasMMX()) {
                 features |= SDL_CPU_MMX;

+ 8 - 4
src/video/SDL_blit_A.c

@@ -1457,18 +1457,22 @@ SDL_CalculateBlitA(SDL_Surface *surface)
                 if (surface->map->identity) {
                     if (df->Gmask == 0x7e0) {
 #ifdef __MMX__
-                        if (SDL_HasMMX())
+                        if (SDL_HasMMX()) {
                             return Blit565to565SurfaceAlphaMMX;
-                        else
+                        } else
 #endif
+                        {
                             return Blit565to565SurfaceAlpha;
+                        }
                     } else if (df->Gmask == 0x3e0) {
 #ifdef __MMX__
-                        if (SDL_HasMMX())
+                        if (SDL_HasMMX()) {
                             return Blit555to555SurfaceAlphaMMX;
-                        else
+                        } else
 #endif
+                        {
                             return Blit555to555SurfaceAlpha;
+                        }
                     }
                 }
                 return BlitNtoNSurfaceAlpha;

+ 3 - 3
src/video/SDL_blit_N.c

@@ -3418,11 +3418,11 @@ SDL_CalculateBlitN(SDL_Surface *surface)
            because RLE is the preferred fast way to deal with this.
            If a particular case turns out to be useful we'll add it. */
 
-        if (srcfmt->BytesPerPixel == 2 && surface->map->identity)
+        if (srcfmt->BytesPerPixel == 2 && surface->map->identity != 0) {
             return Blit2to2Key;
-        else if (dstfmt->BytesPerPixel == 1)
+        } else if (dstfmt->BytesPerPixel == 1) {
             return BlitNto1Key;
-        else {
+        } else {
 #if SDL_ALTIVEC_BLITTERS
             if ((srcfmt->BytesPerPixel == 4) && (dstfmt->BytesPerPixel == 4) && SDL_HasAltiVec()) {
                 return Blit32to32KeyAltivec;

+ 35 - 34
src/video/SDL_bmp.c

@@ -616,11 +616,11 @@ done:
     return surface;
 }
 
-int SDL_SaveBMP_RW(SDL_Surface *saveme, SDL_RWops *dst, int freedst)
+int SDL_SaveBMP_RW(SDL_Surface *surface, SDL_RWops *dst, int freedst)
 {
     Sint64 fp_offset;
     int i, pad;
-    SDL_Surface *surface;
+    SDL_Surface *intermediate_surface;
     Uint8 *bits;
     SDL_bool save32bit = SDL_FALSE;
     SDL_bool saveLegacyBMP = SDL_FALSE;
@@ -657,35 +657,36 @@ int SDL_SaveBMP_RW(SDL_Surface *saveme, SDL_RWops *dst, int freedst)
     Uint32 bV4GammaBlue = 0;
 
     /* Make sure we have somewhere to save */
-    surface = NULL;
+    intermediate_surface = NULL;
     if (dst) {
 #ifdef SAVE_32BIT_BMP
         /* We can save alpha information in a 32-bit BMP */
-        if (saveme->format->BitsPerPixel >= 8 && (saveme->format->Amask ||
-                                                  saveme->map->info.flags & SDL_COPY_COLORKEY)) {
+        if (surface->format->BitsPerPixel >= 8 &&
+            (surface->format->Amask != 0 ||
+             surface->map->info.flags & SDL_COPY_COLORKEY)) {
             save32bit = SDL_TRUE;
         }
 #endif /* SAVE_32BIT_BMP */
 
-        if (saveme->format->palette && !save32bit) {
-            if (saveme->format->BitsPerPixel == 8) {
-                surface = saveme;
+        if (surface->format->palette != NULL && !save32bit) {
+            if (surface->format->BitsPerPixel == 8) {
+                intermediate_surface = surface;
             } else {
                 SDL_SetError("%d bpp BMP files not supported",
-                             saveme->format->BitsPerPixel);
+                             surface->format->BitsPerPixel);
             }
-        } else if ((saveme->format->BitsPerPixel == 24) && !save32bit &&
+        } else if ((surface->format->BitsPerPixel == 24) && !save32bit &&
 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
-                   (saveme->format->Rmask == 0x00FF0000) &&
-                   (saveme->format->Gmask == 0x0000FF00) &&
-                   (saveme->format->Bmask == 0x000000FF)
+                   (surface->format->Rmask == 0x00FF0000) &&
+                   (surface->format->Gmask == 0x0000FF00) &&
+                   (surface->format->Bmask == 0x000000FF)
 #else
-                   (saveme->format->Rmask == 0x000000FF) &&
-                   (saveme->format->Gmask == 0x0000FF00) &&
-                   (saveme->format->Bmask == 0x00FF0000)
+                   (surface->format->Rmask == 0x000000FF) &&
+                   (surface->format->Gmask == 0x0000FF00) &&
+                   (surface->format->Bmask == 0x00FF0000)
 #endif
         ) {
-            surface = saveme;
+            intermediate_surface = surface;
         } else {
             SDL_PixelFormat format;
 
@@ -712,8 +713,8 @@ int SDL_SaveBMP_RW(SDL_Surface *saveme, SDL_RWops *dst, int freedst)
         saveLegacyBMP = SDL_GetHintBoolean(SDL_HINT_BMP_SAVE_LEGACY_FORMAT, SDL_FALSE);
     }
 
-    if (surface && (SDL_LockSurface(surface) == 0)) {
-        const int bw = surface->w * surface->format->BytesPerPixel;
+    if (intermediate_surface && (SDL_LockSurface(intermediate_surface) == 0)) {
+        const int bw = intermediate_surface->w * intermediate_surface->format->BytesPerPixel;
 
         /* Set the BMP file header values */
         bfSize = 0; /* We'll write this when we're done */
@@ -732,16 +733,16 @@ int SDL_SaveBMP_RW(SDL_Surface *saveme, SDL_RWops *dst, int freedst)
 
         /* Set the BMP info values */
         biSize = 40;
-        biWidth = surface->w;
-        biHeight = surface->h;
+        biWidth = intermediate_surface->w;
+        biHeight = intermediate_surface->h;
         biPlanes = 1;
-        biBitCount = surface->format->BitsPerPixel;
+        biBitCount = intermediate_surface->format->BitsPerPixel;
         biCompression = BI_RGB;
-        biSizeImage = surface->h * surface->pitch;
+        biSizeImage = intermediate_surface->h * intermediate_surface->pitch;
         biXPelsPerMeter = 0;
         biYPelsPerMeter = 0;
-        if (surface->format->palette) {
-            biClrUsed = surface->format->palette->ncolors;
+        if (intermediate_surface->format->palette) {
+            biClrUsed = intermediate_surface->format->palette->ncolors;
         } else {
             biClrUsed = 0;
         }
@@ -791,12 +792,12 @@ int SDL_SaveBMP_RW(SDL_Surface *saveme, SDL_RWops *dst, int freedst)
         }
 
         /* Write the palette (in BGR color order) */
-        if (surface->format->palette) {
+        if (intermediate_surface->format->palette) {
             SDL_Color *colors;
             int ncolors;
 
-            colors = surface->format->palette->colors;
-            ncolors = surface->format->palette->ncolors;
+            colors = intermediate_surface->format->palette->colors;
+            ncolors = intermediate_surface->format->palette->ncolors;
             for (i = 0; i < ncolors; ++i) {
                 SDL_RWwrite(dst, &colors[i].b, 1, 1);
                 SDL_RWwrite(dst, &colors[i].g, 1, 1);
@@ -816,10 +817,10 @@ int SDL_SaveBMP_RW(SDL_Surface *saveme, SDL_RWops *dst, int freedst)
         }
 
         /* Write the bitmap image upside down */
-        bits = (Uint8 *)surface->pixels + (surface->h * surface->pitch);
+        bits = (Uint8 *)intermediate_surface->pixels + (intermediate_surface->h * intermediate_surface->pitch);
         pad = ((bw % 4) ? (4 - (bw % 4)) : 0);
-        while (bits > (Uint8 *)surface->pixels) {
-            bits -= surface->pitch;
+        while (bits > (Uint8 *)intermediate_surface->pixels) {
+            bits -= intermediate_surface->pitch;
             if (SDL_RWwrite(dst, bits, 1, bw) != bw) {
                 SDL_Error(SDL_EFWRITE);
                 break;
@@ -843,9 +844,9 @@ int SDL_SaveBMP_RW(SDL_Surface *saveme, SDL_RWops *dst, int freedst)
         }
 
         /* Close it up.. */
-        SDL_UnlockSurface(surface);
-        if (surface != saveme) {
-            SDL_FreeSurface(surface);
+        SDL_UnlockSurface(intermediate_surface);
+        if (intermediate_surface != surface) {
+            SDL_FreeSurface(intermediate_surface);
         }
     }
 

+ 1 - 1
src/video/SDL_egl.c

@@ -162,7 +162,7 @@ int SDL_EGL_SetErrorEx(const char *message, const char *eglFunctionName, EGLint
     char altErrorText[32];
     if (errorText[0] == '\0') {
         /* An unknown-to-SDL error code was reported.  Report its hexadecimal value, instead of its name. */
-        SDL_snprintf(altErrorText, SDL_arraysize(altErrorText), "0x%x", (unsigned int)eglErrorCode);
+        (void)SDL_snprintf(altErrorText, SDL_arraysize(altErrorText), "0x%x", (unsigned int)eglErrorCode);
         errorText = altErrorText;
     }
     return SDL_SetError("%s (call to %s failed, reporting an error of %s)", message, eglFunctionName, errorText);

+ 1 - 1
src/video/SDL_fillrect.c

@@ -333,7 +333,7 @@ int SDL_FillRects(SDL_Surface *dst, const SDL_Rect *rects, int count,
             if (r->x == 0 && r->y == 0 && r->w == dst->w && r->h == dst->h) {
                 if (dst->format->BitsPerPixel == 4) {
                     Uint8 b = (((Uint8)color << 4) | (Uint8)color);
-                    SDL_memset(dst->pixels, b, dst->h * dst->pitch);
+                    SDL_memset(dst->pixels, b, (size_t)dst->h * dst->pitch);
                     return 1;
                 }
             }

+ 8 - 4
src/video/SDL_pixels.c

@@ -569,8 +569,9 @@ int SDL_InitFormat(SDL_PixelFormat *format, Uint32 pixel_format)
         for (mask = Rmask; !(mask & 0x01); mask >>= 1) {
             ++format->Rshift;
         }
-        for (; (mask & 0x01); mask >>= 1)
+        for (; (mask & 0x01); mask >>= 1) {
             --format->Rloss;
+        }
     }
 
     format->Gmask = Gmask;
@@ -580,8 +581,9 @@ int SDL_InitFormat(SDL_PixelFormat *format, Uint32 pixel_format)
         for (mask = Gmask; !(mask & 0x01); mask >>= 1) {
             ++format->Gshift;
         }
-        for (; (mask & 0x01); mask >>= 1)
+        for (; (mask & 0x01); mask >>= 1) {
             --format->Gloss;
+        }
     }
 
     format->Bmask = Bmask;
@@ -591,8 +593,9 @@ int SDL_InitFormat(SDL_PixelFormat *format, Uint32 pixel_format)
         for (mask = Bmask; !(mask & 0x01); mask >>= 1) {
             ++format->Bshift;
         }
-        for (; (mask & 0x01); mask >>= 1)
+        for (; (mask & 0x01); mask >>= 1) {
             --format->Bloss;
+        }
     }
 
     format->Amask = Amask;
@@ -602,8 +605,9 @@ int SDL_InitFormat(SDL_PixelFormat *format, Uint32 pixel_format)
         for (mask = Amask; !(mask & 0x01); mask >>= 1) {
             ++format->Ashift;
         }
-        for (; (mask & 0x01); mask >>= 1)
+        for (; (mask & 0x01); mask >>= 1) {
             --format->Aloss;
+        }
     }
 
     format->palette = NULL;

+ 15 - 16
src/video/SDL_shape.c

@@ -50,17 +50,17 @@ SDL_CreateShapedWindow(const char *title, unsigned int x, unsigned int y, unsign
             SDL_DestroyWindow(result);
             return NULL;
         }
-    } else
-        return NULL;
+    }
+    return NULL;
 }
 
 SDL_bool
 SDL_IsShapedWindow(const SDL_Window *window)
 {
-    if (window == NULL)
+    if (window == NULL) {
         return SDL_FALSE;
-    else
-        return (SDL_bool)(window->shaper != NULL);
+    }
+    return (SDL_bool)(window->shaper != NULL);
 }
 
 /* REQUIRES that bitmap point to a w-by-h bitmap with ppb pixels-per-byte. */
@@ -71,7 +71,7 @@ void SDL_CalculateShapeBitmap(SDL_WindowShapeMode mode, SDL_Surface *shape, Uint
     Uint8 r = 0, g = 0, b = 0, alpha = 0;
     Uint8 *pixel = NULL;
     Uint32 pixel_value = 0, mask_value = 0;
-    int bytes_per_scanline = (shape->w + (ppb - 1)) / ppb;
+    size_t bytes_per_scanline = (size_t)(shape->w + (ppb - 1)) / ppb;
     Uint8 *bitmap_scanline;
     SDL_Color key;
 
@@ -241,8 +241,9 @@ void SDL_TraverseShapeTree(SDL_ShapeTree *tree, SDL_TraversalFunction function,
         SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.upright, function, closure);
         SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.downleft, function, closure);
         SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.downright, function, closure);
-    } else
+    } else {
         function(tree, closure);
+    }
 }
 
 void SDL_FreeShapeTree(SDL_ShapeTree **shape_tree)
@@ -324,17 +325,15 @@ int SDL_GetShapedWindowMode(SDL_Window *window, SDL_WindowShapeMode *shape_mode)
 {
     if (window != NULL && SDL_IsShapedWindow(window)) {
         if (shape_mode == NULL) {
-            if (SDL_WindowHasAShape(window))
-                /* The window given has a shape. */
-                return 0;
-            else
-                /* The window given is shapeable but lacks a shape. */
-                return SDL_WINDOW_LACKS_SHAPE;
+            if (SDL_WindowHasAShape(window)) {
+                return 0; /* The window given has a shape. */
+            } else {
+                return SDL_WINDOW_LACKS_SHAPE; /* The window given is shapeable but lacks a shape. */
+            }
         } else {
             *shape_mode = window->shaper->mode;
             return 0;
         }
-    } else
-        /* The window given is not a valid shapeable window. */
-        return SDL_NONSHAPEABLE_WINDOW;
+    }
+    return SDL_NONSHAPEABLE_WINDOW; /* The window given is not a valid shapeable window. */
 }

+ 15 - 10
src/video/SDL_video.c

@@ -304,7 +304,7 @@ static int SDL_CreateWindowTexture(SDL_VideoDevice *_this, SDL_Window *window, U
                                       window->w, window->h);
     if (!data->texture) {
         /* codechecker_false_positive [Malloc] Static analyzer doesn't realize allocated `data` is saved to SDL_WINDOWTEXTUREDATA and not leaked here. */
-        return -1;
+        return -1; /* NOLINT(clang-analyzer-unix.Malloc) */
     }
 
     /* Create framebuffer data */
@@ -313,7 +313,7 @@ static int SDL_CreateWindowTexture(SDL_VideoDevice *_this, SDL_Window *window, U
 
     {
         /* Make static analysis happy about potential SDL_malloc(0) calls. */
-        const size_t allocsize = window->h * data->pitch;
+        const size_t allocsize = (size_t)window->h * data->pitch;
         data->pixels = SDL_malloc((allocsize > 0) ? allocsize : 1);
         if (!data->pixels) {
             return SDL_OutOfMemory();
@@ -1576,6 +1576,11 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
         if (SDL_Init(SDL_INIT_VIDEO) < 0) {
             return NULL;
         }
+
+        /* Make clang-tidy happy */
+        if (_this == NULL) {
+            return NULL;
+        }
     }
 
     /* ensure no more than one of these flags is set */
@@ -3997,7 +4002,7 @@ SDL_GL_CreateContext(SDL_Window *window)
     return ctx;
 }
 
-int SDL_GL_MakeCurrent(SDL_Window *window, SDL_GLContext ctx)
+int SDL_GL_MakeCurrent(SDL_Window *window, SDL_GLContext context)
 {
     int retval;
 
@@ -4006,12 +4011,12 @@ int SDL_GL_MakeCurrent(SDL_Window *window, SDL_GLContext ctx)
     }
 
     if (window == SDL_GL_GetCurrentWindow() &&
-        ctx == SDL_GL_GetCurrentContext()) {
+        context == SDL_GL_GetCurrentContext()) {
         /* We're already current. */
         return 0;
     }
 
-    if (!ctx) {
+    if (!context) {
         window = NULL;
     } else if (window) {
         CHECK_WINDOW_MAGIC(window, -1);
@@ -4023,12 +4028,12 @@ int SDL_GL_MakeCurrent(SDL_Window *window, SDL_GLContext ctx)
         return SDL_SetError("Use of OpenGL without a window is not supported on this platform");
     }
 
-    retval = _this->GL_MakeCurrent(_this, window, ctx);
+    retval = _this->GL_MakeCurrent(_this, window, context);
     if (retval == 0) {
         _this->current_glwin = window;
-        _this->current_glctx = ctx;
+        _this->current_glctx = context;
         SDL_TLSSet(_this->current_glwin_tls, window, NULL);
-        SDL_TLSSet(_this->current_glctx_tls, ctx, NULL);
+        SDL_TLSSet(_this->current_glctx_tls, context, NULL);
     }
     return retval;
 }
@@ -4570,7 +4575,7 @@ SDL_ShouldAllowTopmost(void)
     return SDL_GetHintBoolean(SDL_HINT_ALLOW_TOPMOST, SDL_TRUE);
 }
 
-int SDL_SetWindowHitTest(SDL_Window *window, SDL_HitTest callback, void *userdata)
+int SDL_SetWindowHitTest(SDL_Window *window, SDL_HitTest callback, void *callback_data)
 {
     CHECK_WINDOW_MAGIC(window, -1);
 
@@ -4581,7 +4586,7 @@ int SDL_SetWindowHitTest(SDL_Window *window, SDL_HitTest callback, void *userdat
     }
 
     window->hit_test = callback;
-    window->hit_test_data = userdata;
+    window->hit_test_data = callback_data;
 
     return 0;
 }

+ 2 - 2
src/video/SDL_vulkan_utils.c

@@ -231,8 +231,8 @@ SDL_bool SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_,
         SDL_SetError(VK_KHR_DISPLAY_EXTENSION_NAME " extension is not enabled in the Vulkan instance.");
         goto error;
     }
-
-    if ((chosenDisplayId = SDL_getenv("SDL_VULKAN_DISPLAY")) != NULL) {
+    chosenDisplayId = SDL_getenv("SDL_VULKAN_DISPLAY");
+    if (chosenDisplayId != NULL) {
         displayId = SDL_atoi(chosenDisplayId);
     }
 

Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff