From d0bbfdbfb881e5407911d84c12899bd5b442a130 Mon Sep 17 00:00:00 2001
From: Pierre Wendling <[EMAIL REDACTED]>
Date: Thu, 1 Dec 2022 16:07:03 -0500
Subject: [PATCH] Clang-Tidy fixes (#6725)
(cherry picked from commit 3c501b963dd8f0605a6ce7978882df39ba76f9cd)
---
include/SDL_audio.h | 12 +-
include/SDL_mutex.h | 4 +-
include/SDL_power.h | 7 +-
include/SDL_surface.h | 2 +-
src/SDL_assert.c | 4 +-
src/SDL_error.c | 2 +-
src/SDL_log.c | 20 +-
src/audio/SDL_audio.c | 59 ++++--
src/audio/SDL_audiocvt.c | 45 ++---
src/audio/SDL_audiodev.c | 11 +-
src/audio/SDL_audiotypecvt.c | 2 +-
src/audio/SDL_wave.c | 8 +-
src/audio/alsa/SDL_alsa_audio.c | 19 +-
src/audio/coreaudio/SDL_coreaudio.m | 40 ++--
src/audio/dsp/SDL_dspaudio.c | 4 +-
src/audio/jack/SDL_jackaudio.c | 14 +-
src/audio/pipewire/SDL_pipewire.c | 23 +--
src/audio/sndio/SDL_sndioaudio.c | 35 ++--
src/core/android/SDL_android.c | 1 -
src/core/linux/SDL_evdev.c | 12 +-
src/core/linux/SDL_evdev_capabilities.c | 8 +-
src/core/linux/SDL_evdev_capabilities.h | 8 +-
src/core/linux/SDL_evdev_kbd.c | 98 +++++-----
src/core/linux/SDL_fcitx.c | 4 +-
src/core/linux/SDL_ibus.c | 10 +-
src/core/windows/SDL_windows.c | 8 +-
src/events/SDL_events.c | 180 +++++++++---------
src/events/SDL_keyboard.c | 7 +-
src/events/SDL_keyboard_c.h | 2 +-
src/events/SDL_mouse.c | 2 +-
src/events/SDL_quit.c | 2 +-
src/file/SDL_rwops.c | 2 +-
src/file/cocoa/SDL_rwopsbundlesupport.m | 2 +-
src/filesystem/unix/SDL_sysfilesystem.c | 4 +-
src/haptic/SDL_haptic.c | 9 +-
src/haptic/android/SDL_syshaptic.c | 5 +-
src/haptic/darwin/SDL_syshaptic.c | 3 +-
src/haptic/linux/SDL_syshaptic.c | 7 +-
src/haptic/windows/SDL_dinputhaptic.c | 41 ++--
src/haptic/windows/SDL_xinputhaptic.c | 4 +-
src/hidapi/SDL_hidapi.c | 59 +++---
src/joystick/SDL_gamecontroller.c | 76 ++++----
src/joystick/SDL_joystick.c | 6 +-
src/joystick/darwin/SDL_iokitjoystick.c | 5 +-
src/joystick/hidapi/SDL_hidapi_gamecube.c | 2 +-
src/joystick/hidapi/SDL_hidapi_ps3.c | 11 +-
src/joystick/hidapi/SDL_hidapi_ps4.c | 20 +-
src/joystick/hidapi/SDL_hidapi_ps5.c | 12 +-
src/joystick/hidapi/SDL_hidapi_shield.c | 2 +-
src/joystick/hidapi/SDL_hidapi_steam.c | 27 +--
src/joystick/hidapi/SDL_hidapi_switch.c | 23 +--
src/joystick/hidapi/SDL_hidapi_xboxone.c | 10 +-
src/joystick/hidapi/SDL_hidapijoystick.c | 10 +-
src/joystick/iphoneos/SDL_mfijoystick.m | 31 +--
src/joystick/linux/SDL_sysjoystick.c | 6 +-
src/joystick/virtual/SDL_virtualjoystick.c | 1 -
src/joystick/windows/SDL_dinputjoystick.c | 14 +-
src/joystick/windows/SDL_rawinputjoystick.c | 8 +-
.../windows/SDL_windows_gaming_input.c | 6 +-
src/joystick/windows/SDL_windowsjoystick.c | 6 +-
src/joystick/windows/SDL_xinputjoystick.c | 28 +--
src/locale/macosx/SDL_syslocale.m | 3 +-
src/locale/windows/SDL_syslocale.c | 2 +-
src/main/windows/SDL_windows_main.c | 4 +-
src/misc/SDL_url.c | 2 -
src/power/linux/SDL_syspower.c | 2 +-
src/render/SDL_render.c | 20 +-
src/render/SDL_yuv_sw.c | 8 +-
src/render/direct3d/SDL_render_d3d.c | 29 +--
src/render/direct3d11/SDL_render_d3d11.c | 16 +-
src/render/direct3d12/SDL_render_d3d12.c | 18 +-
src/render/metal/SDL_render_metal.m | 2 +-
src/render/opengl/SDL_render_gl.c | 11 +-
src/render/opengl/SDL_shaders_gl.c | 2 +-
src/render/opengles2/SDL_render_gles2.c | 11 +-
src/render/software/SDL_render_sw.c | 8 +-
src/render/software/SDL_rotate.c | 2 +-
src/render/software/SDL_triangle.c | 27 ++-
src/stdlib/SDL_mslibc.c | 4 +
src/stdlib/SDL_string.c | 21 +-
src/test/SDL_test_assert.c | 6 +-
src/test/SDL_test_common.c | 100 +++++-----
src/test/SDL_test_compare.c | 10 +-
src/test/SDL_test_font.c | 2 +-
src/test/SDL_test_harness.c | 6 +-
src/test/SDL_test_log.c | 13 +-
src/test/SDL_test_memory.c | 10 +-
src/thread/SDL_thread.c | 10 +-
src/thread/pthread/SDL_syscond.c | 2 +-
src/video/SDL_RLEaccel.c | 60 +++---
src/video/SDL_blit.c | 2 +-
src/video/SDL_blit_A.c | 12 +-
src/video/SDL_blit_N.c | 6 +-
src/video/SDL_bmp.c | 69 +++----
src/video/SDL_egl.c | 2 +-
src/video/SDL_fillrect.c | 2 +-
src/video/SDL_pixels.c | 12 +-
src/video/SDL_shape.c | 31 ++-
src/video/SDL_video.c | 25 ++-
src/video/SDL_vulkan_utils.c | 4 +-
src/video/SDL_yuv.c | 12 +-
src/video/android/SDL_androidmouse.c | 2 +-
src/video/cocoa/SDL_cocoaevents.m | 6 +-
src/video/cocoa/SDL_cocoakeyboard.m | 3 +-
src/video/cocoa/SDL_cocoametalview.m | 3 +-
src/video/dummy/SDL_nullframebuffer.c | 4 +-
src/video/kmsdrm/SDL_kmsdrmdyn.c | 3 -
src/video/kmsdrm/SDL_kmsdrmmouse.c | 4 +-
src/video/kmsdrm/SDL_kmsdrmvideo.c | 16 +-
.../offscreen/SDL_offscreenframebuffer.c | 4 +-
src/video/wayland/SDL_waylanddatamanager.c | 33 ++--
src/video/wayland/SDL_waylandevents.c | 14 +-
src/video/wayland/SDL_waylandmessagebox.c | 2 +-
src/video/wayland/SDL_waylandvideo.c | 9 +-
src/video/windows/SDL_windowsevents.c | 17 +-
src/video/windows/SDL_windowsframebuffer.c | 2 +-
src/video/windows/SDL_windowskeyboard.c | 31 +--
src/video/windows/SDL_windowsmessagebox.c | 8 +-
src/video/windows/SDL_windowsmodes.c | 1 +
src/video/windows/SDL_windowsmouse.c | 4 +-
src/video/windows/SDL_windowsshape.c | 3 +-
src/video/windows/SDL_windowsvulkan.c | 2 +-
src/video/windows/SDL_windowswindow.c | 20 +-
src/video/windows/SDL_windowswindow.h | 4 +-
src/video/x11/SDL_x11events.c | 8 +-
src/video/x11/SDL_x11framebuffer.c | 11 +-
src/video/x11/SDL_x11keyboard.c | 13 +-
src/video/x11/SDL_x11messagebox.c | 7 +-
src/video/x11/SDL_x11modes.c | 2 +-
src/video/x11/SDL_x11mouse.c | 10 +-
src/video/x11/SDL_x11shape.h | 2 +-
src/video/x11/SDL_x11video.c | 5 +-
src/video/x11/SDL_x11window.c | 16 +-
src/video/x11/SDL_x11window.h | 2 +-
test/checkkeys.c | 2 +-
test/checkkeysthreads.c | 28 ++-
test/controllermap.c | 13 +-
test/loopwavequeue.c | 8 +-
test/testatomic.c | 12 +-
test/testaudiohotplug.c | 12 +-
test/testaudioinfo.c | 11 +-
test/testautomation.c | 2 +-
test/testautomation_audio.c | 14 +-
test/testautomation_clipboard.c | 8 +-
test/testautomation_keyboard.c | 4 +-
test/testautomation_math.c | 2 +-
test/testautomation_platform.c | 8 +-
test/testautomation_rect.c | 28 +--
test/testautomation_rwops.c | 10 +-
test/testautomation_sdltest.c | 55 +++---
test/testautomation_stdlib.c | 2 +-
test/testautomation_video.c | 6 +-
test/testcustomcursor.c | 5 +-
test/testdisplayinfo.c | 2 +-
test/testfile.c | 16 +-
test/testgamecontroller.c | 2 +-
test/testgles2.c | 2 +-
test/testiconv.c | 4 +-
test/testime.c | 43 +++--
test/testintersections.c | 16 +-
test/testloadso.c | 2 -
test/testlock.c | 20 +-
test/testmultiaudio.c | 1 -
test/testnative.c | 2 +-
test/testoverlay2.c | 1 +
test/testpower.c | 3 +-
test/testqsort.c | 5 +-
test/testresample.c | 2 +-
test/testsem.c | 16 +-
test/testsensor.c | 2 +-
test/testshader.c | 6 +-
test/testshape.c | 4 +-
test/testthread.c | 4 +-
test/testutils.c | 2 +-
test/testvulkan.c | 4 +-
test/testwm2.c | 8 +-
test/testyuv.c | 2 +-
test/testyuv_cvt.c | 2 +-
test/torturethread.c | 6 +-
179 files changed, 1259 insertions(+), 1100 deletions(-)
diff --git a/include/SDL_audio.h b/include/SDL_audio.h
index c42de3ed97b3..4b2147bb8161 100644
--- a/include/SDL_audio.h
+++ b/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.
diff --git a/include/SDL_mutex.h b/include/SDL_mutex.h
index 173468f6ace6..d4d55a4bf5f0 100644
--- a/include/SDL_mutex.h
+++ b/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.
diff --git a/include/SDL_power.h b/include/SDL_power.h
index ecb3f4b02343..09684e98acaf 100644
--- a/include/SDL_power.h
+++ b/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
diff --git a/include/SDL_surface.h b/include/SDL_surface.h
index 838de654eed7..561b2be188cf 100644
--- a/include/SDL_surface.h
+++ b/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
diff --git a/src/SDL_assert.c b/src/SDL_assert.c
index c4ca82407d5f..a689a550b940 100644
--- a/src/SDL_assert.c
+++ b/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;
}
diff --git a/src/SDL_error.c b/src/SDL_error.c
index be3160c5d637..fc9a490c689e 100644
--- a/src/SDL_error.c
+++ b/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);
}
}
diff --git a/src/SDL_log.c b/src/SDL_log.c
index 59f763820b94..e9199cc2e652 100644
--- a/src/SDL_log.c
+++ b/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 && \
diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c
index 52ed792718b4..959ce0d7a162 100644
--- a/src/audio/SDL_audio.c
+++ b/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) {
diff --git a/src/audio/SDL_audiocvt.c b/src/audio/SDL_audiocvt.c
index b0a8a70725ab..a687aec19ab7 100644
--- a/src/audio/SDL_audiocvt.c
+++ b/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);
}
diff --git a/src/audio/SDL_audiodev.c b/src/audio/SDL_audiodev.c
index d5c61d84d5e3..930e900a73f3 100644
--- a/src/audio/SDL_audiodev.c
+++ b/src/audio/SDL_audiode
(Patch may be truncated, please check the link at the top of this post.)