SDL_mixer: fix -Wsign-compare warnings

From f02bb84163cc9c747d710c4e7e54e7cbd7747f1f Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Fri, 9 Jan 2026 01:24:04 +0300
Subject: [PATCH] fix -Wsign-compare warnings

---
 src/SDL_mixer.c               | 10 +++++-----
 src/SDL_mixer_metadata_tags.c |  2 +-
 src/decoder_drflac.c          | 14 +++++++-------
 src/decoder_flac.c            |  4 ++--
 src/decoder_opus.c            |  4 ++--
 src/decoder_stb_vorbis.c      |  6 +++---
 src/decoder_timidity.c        |  2 +-
 src/decoder_voc.c             |  6 +++---
 src/decoder_vorbis.c          |  4 ++--
 src/decoder_wav.c             | 10 +++++-----
 test/testaudiodecoder.c       |  2 +-
 11 files changed, 32 insertions(+), 32 deletions(-)

diff --git a/src/SDL_mixer.c b/src/SDL_mixer.c
index e09eadc70..11bbe8335 100644
--- a/src/SDL_mixer.c
+++ b/src/SDL_mixer.c
@@ -345,7 +345,7 @@ static void SDLCALL TrackGetCallback(void *userdata, SDL_AudioStream *stream, in
     }
 
     // do we need to grow our buffer?
-    if (additional_amount > track->input_buffer_len) {
+    if ((unsigned)additional_amount > track->input_buffer_len) {
         void *ptr = SDL_realloc(track->input_buffer, additional_amount);
         if (!ptr) {   // uhoh.
             TrackStopped(track);
@@ -541,7 +541,7 @@ static void SDLCALL MixerCallback(void *userdata, SDL_AudioStream *stream, int a
     const bool skip_group_mixing = !mixer->all_groups || !mixer->all_groups->next;
     const int alloc_multiplier = skip_group_mixing ? 2 : 3;
     const int alloc_size = additional_amount * alloc_multiplier;
-    if (alloc_size > mixer->mix_buffer_allocation) {
+    if ((unsigned)alloc_size > mixer->mix_buffer_allocation) {
         void *ptr = SDL_realloc(mixer->mix_buffer, alloc_size);
         if (!ptr) {   // uhoh.
             return;  // not much to be done, we're out of memory!
@@ -1857,7 +1857,7 @@ static void SDLCALL GetTrackTagsCallback(void *userdata, SDL_PropertiesID props,
     if (data->failed) {
         return;  // just get out if we previously failed.
     } else if (SDL_GetBooleanProperty(props, tag, false)) {   // if false, tag _was_ here, but has since been untagged. Skip it.
-        if (data->count < SDL_arraysize(data->struct_tags)) {
+        if (data->count < (int)SDL_arraysize(data->struct_tags)) {
             data->struct_tags[data->count++] = tag;
         } else {
             void *ptr = SDL_realloc(data->allocated_tags, sizeof (char *) * (data->count - SDL_arraysize(data->struct_tags) + 1));
@@ -1892,14 +1892,14 @@ char **MIX_GetTrackTags(MIX_Track *track, int *count)
     if (!data.failed) {
         size_t allocation = sizeof (char *);  // one extra pointer for the list's NULL terminator.
         for (int i = 0; i < data.count; i++) {
-            const char *str = (i < SDL_arraysize(data.struct_tags)) ? data.struct_tags[i] : data.allocated_tags[i - SDL_arraysize(data.struct_tags)];
+            const char *str = (i < (int)SDL_arraysize(data.struct_tags)) ? data.struct_tags[i] : data.allocated_tags[i - SDL_arraysize(data.struct_tags)];
             allocation += sizeof (char *) + SDL_strlen(str) + 1;
         }
         retval = (char **) SDL_malloc(allocation);
         if (retval) {
             char *strptr = ((char *) retval) + (sizeof (char *) * (data.count + 1));
             for (int i = 0; i < data.count; i++) {
-                const char *str = (i < SDL_arraysize(data.struct_tags)) ? data.struct_tags[i] : data.allocated_tags[i - SDL_arraysize(data.struct_tags)];
+                const char *str = (i < (int)SDL_arraysize(data.struct_tags)) ? data.struct_tags[i] : data.allocated_tags[i - SDL_arraysize(data.struct_tags)];
                 const size_t slen = SDL_strlen(str) + 1;
                 SDL_memcpy(strptr, str, slen);
                 retval[i] = strptr;
diff --git a/src/SDL_mixer_metadata_tags.c b/src/SDL_mixer_metadata_tags.c
index f83444ec0..809c841f4 100644
--- a/src/SDL_mixer_metadata_tags.c
+++ b/src/SDL_mixer_metadata_tags.c
@@ -598,7 +598,7 @@ static Uint32 ape_handle_tag(SDL_PropertiesID props, Uint8 *data, size_t valsize
         apekey[key_len] = '\0';
         char generic_key[256];
         const int rc = SDL_snprintf(generic_key, sizeof (generic_key), "SDL_mixer.metadata.ape.%s", apekey);
-        if ((rc > 0) && (rc < sizeof (generic_key))) {
+        if ((rc > 0) && (rc < (int)sizeof(generic_key))) {
             if (!SDL_HasProperty(props, generic_key)) {  // in case there are multiple ID3v1 tags appended to a file, we'll take the last one, since we parse backwards from the end of file.
                 SDL_SetStringProperty(props, generic_key, value);
             }
diff --git a/src/decoder_drflac.c b/src/decoder_drflac.c
index e5ae09472..c92913495 100644
--- a/src/decoder_drflac.c
+++ b/src/decoder_drflac.c
@@ -176,14 +176,14 @@ static bool SDLCALL DRFLAC_init_audio(SDL_IOStream *io, SDL_AudioSpec *spec, SDL
 
     adata->framesize = SDL_AUDIO_FRAMESIZE(*spec);
 
-    if (adata->loop.end > decoder->totalPCMFrameCount) {
+    if (adata->loop.end > (Sint64)decoder->totalPCMFrameCount) {
         adata->loop.active = false;
     }
 
     if (decoder->totalPCMFrameCount == 0) {
         *duration_frames = MIX_DURATION_UNKNOWN;
     } else if (adata->loop.active) {
-        *duration_frames = (adata->loop.count < 0) ? MIX_DURATION_INFINITE : (decoder->totalPCMFrameCount * adata->loop.count);
+        *duration_frames = (adata->loop.count < 0) ? MIX_DURATION_INFINITE : ((Sint64)decoder->totalPCMFrameCount * adata->loop.count);
     } else {
         *duration_frames = decoder->totalPCMFrameCount;
     }
@@ -230,7 +230,7 @@ static bool SDLCALL DRFLAC_decode(void *track_userdata, SDL_AudioStream *stream)
 
     const MIX_OggLoop *loop = &tdata->adata->loop;
     if (tdata->current_iteration < 0) {
-        if (loop->active && ((tdata->current_iteration_frames + amount) >= loop->start)) {
+        if (loop->active && ((tdata->current_iteration_frames + (Sint64)amount) >= loop->start)) {
             tdata->current_iteration = 0;  // we've hit the start of the loop point.
             tdata->current_iteration_frames = (tdata->current_iteration_frames - loop->start);  // so adding `amount` corrects this later.
         }
@@ -240,12 +240,12 @@ static bool SDLCALL DRFLAC_decode(void *track_userdata, SDL_AudioStream *stream)
         SDL_assert(loop->active);
         SDL_assert(tdata->current_iteration_frames <= loop->len);
         const Sint64 available = loop->len - tdata->current_iteration_frames;
-        if (amount > available) {
+        if ((Sint64)amount > available) {
             amount = available;
         }
 
         SDL_assert(tdata->current_iteration_frames <= loop->len);
-        if ((tdata->current_iteration_frames + amount) >= loop->len) {  // time to loop?
+        if ((tdata->current_iteration_frames + (Sint64)amount) >= loop->len) {  // time to loop?
             bool should_loop = false;
             if (loop->count < 0) {  // negative==infinite loop
                 tdata->current_iteration = 0;
@@ -286,9 +286,9 @@ static bool SDLCALL DRFLAC_seek(void *track_userdata, Uint64 frame)
     Sint64 final_iteration_frames = 0;
 
     // frame has hit the loop point?
-    if (loop->active && (frame >= loop->start)) {
+    if (loop->active && ((Sint64)frame >= loop->start)) {
         // figure out the _actual_ frame in the vorbis file we're aiming for.
-        if ((loop->count < 0) || (frame < (loop->len * loop->count))) {  // literally in the loop right now.
+        if ((loop->count < 0) || ((Sint64)frame < (loop->len * loop->count))) {  // literally in the loop right now.
             frame -= loop->start;  // make logical frame index relative to start of loop.
             final_iteration = (loop->count < 0) ? 0 : (frame / loop->len);  // decide what iteration of the loop we're on (stays at zero for infinite loops).
             frame %= loop->len;  // drop iterations so we're an offset into the loop.
diff --git a/src/decoder_flac.c b/src/decoder_flac.c
index 90c3b3f9b..a2229d7d2 100644
--- a/src/decoder_flac.c
+++ b/src/decoder_flac.c
@@ -457,9 +457,9 @@ static bool SDLCALL FLAC_seek(void *track_userdata, Uint64 frame)
     Sint64 final_iteration_frames = 0;
 
     // frame has hit the loop point?
-    if (loop->active && (frame >= loop->start)) {
+    if (loop->active && ((Sint64)frame >= loop->start)) {
         // figure out the _actual_ frame in the vorbis file we're aiming for.
-        if ((loop->count < 0) || (frame < (loop->len * loop->count))) {  // literally in the loop right now.
+        if ((loop->count < 0) || ((Sint64)frame < (loop->len * loop->count))) {  // literally in the loop right now.
             frame -= loop->start;  // make logical frame index relative to start of loop.
             final_iteration = (loop->count < 0) ? 0 : (frame / loop->len);  // decide what iteration of the loop we're on (stays at zero for infinite loops).
             frame %= loop->len;  // drop iterations so we're an offset into the loop.
diff --git a/src/decoder_opus.c b/src/decoder_opus.c
index 0a472cddf..d38ffd48c 100644
--- a/src/decoder_opus.c
+++ b/src/decoder_opus.c
@@ -311,9 +311,9 @@ static bool SDLCALL OPUS_seek(void *track_userdata, Uint64 frame)
     Sint64 final_iteration_frames = 0;
 
     // frame has hit the loop point?
-    if (loop->active && (frame >= loop->start)) {
+    if (loop->active && ((Sint64)frame >= loop->start)) {
         // figure out the _actual_ frame in the vorbis file we're aiming for.
-        if ((loop->count < 0) || (frame < (loop->len * loop->count))) {  // literally in the loop right now.
+        if ((loop->count < 0) || ((Sint64)frame < (loop->len * loop->count))) {  // literally in the loop right now.
             frame -= loop->start;  // make logical frame index relative to start of loop.
             final_iteration = (loop->count < 0) ? 0 : (frame / loop->len);  // decide what iteration of the loop we're on (stays at zero for infinite loops).
             frame %= loop->len;  // drop iterations so we're an offset into the loop.
diff --git a/src/decoder_stb_vorbis.c b/src/decoder_stb_vorbis.c
index 7c1a41974..e7115e182 100644
--- a/src/decoder_stb_vorbis.c
+++ b/src/decoder_stb_vorbis.c
@@ -233,7 +233,7 @@ static bool SDLCALL STBVORBIS_decode(void *track_userdata, SDL_AudioStream *stre
     float *outputs[8];
     if (tdata->skip_samples) {
         const Uint32 skip = tdata->skip_samples;
-        if (skip >= amount) {
+        if (skip >= (unsigned)amount) {
             tdata->skip_samples -= amount;
             return true;  // throw this all away; just try again next iteration.
         }
@@ -304,9 +304,9 @@ static bool SDLCALL STBVORBIS_seek(void *track_userdata, Uint64 frame)
     Sint64 final_iteration_frames = 0;
 
     // frame has hit the loop point?
-    if (loop->active && (frame >= loop->start)) {
+    if (loop->active && ((Sint64)frame >= loop->start)) {
         // figure out the _actual_ frame in the vorbis file we're aiming for.
-        if ((loop->count < 0) || (frame < (loop->len * loop->count))) {  // literally in the loop right now.
+        if ((loop->count < 0) || ((Sint64)frame < (loop->len * loop->count))) {  // literally in the loop right now.
             frame -= loop->start;  // make logical frame index relative to start of loop.
             final_iteration = (loop->count < 0) ? 0 : (frame / loop->len);  // decide what iteration of the loop we're on (stays at zero for infinite loops).
             frame %= loop->len;  // drop iterations so we're an offset into the loop.
diff --git a/src/decoder_timidity.c b/src/decoder_timidity.c
index 35b0c5f46..d27bc3236 100644
--- a/src/decoder_timidity.c
+++ b/src/decoder_timidity.c
@@ -51,7 +51,7 @@ static bool SDLCALL TIMIDITY_init(void)
         return (Timidity_Init(cfg) == 0); // env or user override: no other tries
     }
 
-    for (int i = 0; i < SDL_arraysize(timidity_cfgs); i++) {
+    for (int i = 0; i < (int)SDL_arraysize(timidity_cfgs); i++) {
         if (Timidity_Init(timidity_cfgs[i]) == 0) {
             return true;
         }
diff --git a/src/decoder_voc.c b/src/decoder_voc.c
index 635cd6511..9fbe5b697 100644
--- a/src/decoder_voc.c
+++ b/src/decoder_voc.c
@@ -40,7 +40,7 @@
 typedef struct VOC_Block
 {
     int loop_count;  // 0=data or silence block, >0=loop block of X loops, -1=infinite loop block, -2=endloop block.
-    Uint64 iopos;  // byte position in i/o stream of this block's data. Might be 0 for things like loop and silence blocks.
+    Sint64 iopos;  // byte position in i/o stream of this block's data. Might be 0 for things like loop and silence blocks.
     SDL_AudioSpec spec;
     Uint64 frames;
 } VOC_Block;
@@ -85,7 +85,7 @@ static VOC_Block *AddVocDataBlock(VOC_AudioData *adata, Sint64 iopos, const SDL_
 
     VOC_Block *block = AddVocBlock(adata);
     if (block) {
-        block->iopos = (Uint64) iopos;
+        block->iopos = iopos;
         block->loop_count = 0;
         SDL_copyp(&block->spec, spec);
         block->frames = frames;
@@ -532,7 +532,7 @@ static bool SDLCALL VOC_seek(void *userdata, Uint64 frame)
                 SDL_assert(frame >= framepos);
                 tdata->frame_pos = frame - framepos;
                 if (block->iopos) {  // have to read actual file data from this block.
-                    if (SDL_SeekIO(tdata->io, block->iopos + (tdata->frame_pos * framesize), SDL_IO_SEEK_SET) < 0) {
+                    if (SDL_SeekIO(tdata->io, block->iopos + ((Sint64)tdata->frame_pos * framesize), SDL_IO_SEEK_SET) < 0) {
                         return false;  // uhoh.
                     }
                 }
diff --git a/src/decoder_vorbis.c b/src/decoder_vorbis.c
index d71c753bb..8abb55f52 100644
--- a/src/decoder_vorbis.c
+++ b/src/decoder_vorbis.c
@@ -351,9 +351,9 @@ static bool SDLCALL VORBIS_seek(void *track_userdata, Uint64 frame)
     Sint64 final_iteration_frames = 0;
 
     // frame has hit the loop point?
-    if (loop->active && (frame >= loop->start)) {
+    if (loop->active && ((Sint64)frame >= loop->start)) {
         // figure out the _actual_ frame in the vorbis file we're aiming for.
-        if ((loop->count < 0) || (frame < (loop->len * loop->count))) {  // literally in the loop right now.
+        if ((loop->count < 0) || ((Sint64)frame < (loop->len * loop->count))) {  // literally in the loop right now.
             frame -= loop->start;  // make logical frame index relative to start of loop.
             final_iteration = (loop->count < 0) ? 0 : (frame / loop->len);  // decide what iteration of the loop we're on (stays at zero for infinite loops).
             frame %= loop->len;  // drop iterations so we're an offset into the loop.
diff --git a/src/decoder_wav.c b/src/decoder_wav.c
index 0641861ea..a6e9a0303 100644
--- a/src/decoder_wav.c
+++ b/src/decoder_wav.c
@@ -1143,7 +1143,7 @@ static bool BuildSeekBlocks(WAV_AudioData *adata)
         current_frame += seekblocks->num_frames;
         seekblocks++;
 
-        for (int i = 0; i < numloops; i++) {
+        for (unsigned int i = 0; i < numloops; i++) {
             // space covered by a loop...
             const WAVLoopPoint *loop = &adata->loops[i];
             seekblocks->frame_start = current_frame;
@@ -1442,7 +1442,7 @@ static bool SDLCALL WAV_decode(void *track_userdata, SDL_AudioStream *stream)
         } else {
             //SDL_Log("That was the last iteration, moving to next seekblock!");
             seekblock++;
-            if ((seekblock - tdata->adata->seekblocks) >= tdata->adata->num_seekblocks) {  // ran out of blocks! EOF!!
+            if ((seekblock - tdata->adata->seekblocks) >= (Sint64)tdata->adata->num_seekblocks) {  // ran out of blocks! EOF!!
                 //SDL_Log("That was the last seekblock, too!");
                 tdata->current_iteration--;
                 return false;
@@ -1464,7 +1464,7 @@ static bool SDLCALL WAV_decode(void *track_userdata, SDL_AudioStream *stream)
         buflen -= mod;
     }
 
-    buflen = SDL_min(buflen, available_bytes);
+    buflen = SDL_min(buflen, (Sint64)available_bytes);
     SDL_assert(buflen > 0);  // we should have caught this in the seekblock code.
 
     const int br = tdata->adata->fetch(tdata, buffer, buflen);  // this will deal with different formats that might need decompression or conversion.
@@ -1487,7 +1487,7 @@ static bool FindWAVSeekBlock(const WAVSeekBlock *seekblocks, int num_seekblocks,
     SDL_assert(result != NULL);
 
     const Sint64 frame = (Sint64) ui64frame;
-    for (unsigned int i = 0; i < num_seekblocks; i++) {
+    for (int i = 0; i < num_seekblocks; i++) {
         const WAVSeekBlock *seekblock = &seekblocks[i];
         const Sint64 frame_start = seekblock->frame_start;
         const Sint64 num_frames = seekblock->num_frames;
@@ -1544,7 +1544,7 @@ static bool SDLCALL WAV_seek(void *track_userdata, Uint64 frame)
         int remainder = ((int)(frame % adata->adpcm_info.samplesperblock)) * adata->decoded_framesize;
         while (remainder > 0) {
             Uint8 buffer[1024];
-            const int br = adata->fetch(tdata, buffer, SDL_min(remainder, sizeof (buffer)));
+            const int br = adata->fetch(tdata, buffer, SDL_min(remainder, (int)sizeof(buffer)));
             if (br <= 0) {
                 return false;
             }
diff --git a/test/testaudiodecoder.c b/test/testaudiodecoder.c
index c779442e1..9f6365d5f 100644
--- a/test/testaudiodecoder.c
+++ b/test/testaudiodecoder.c
@@ -15,7 +15,7 @@ static void SDLCALL AudioDeviceCallback(void *userdata, SDL_AudioStream *stream,
 
     Uint8 buffer[1024];
     while (additional_amount > 0) {
-        const int needed = SDL_min(sizeof (buffer), additional_amount);
+        const int needed = SDL_min((int)sizeof(buffer), additional_amount);
         const int br = MIX_DecodeAudio(audiodecoder, buffer, needed, &spec);
         if (br <= 0) {
             done = true;