From fc4e1623d323d94f7eb7450ae784aa912970b2eb Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Sat, 28 Feb 2026 06:23:00 +0300
Subject: [PATCH] change some `x == -1` checks into `x < 0` for simplicity
---
src/SDL_mixer.c | 10 +++++-----
src/SDL_mixer_metadata_tags.c | 36 +++++++++++++++++------------------
src/decoder_drflac.c | 2 +-
src/decoder_fluidsynth.c | 2 +-
src/decoder_gme.c | 2 +-
src/decoder_timidity.c | 4 ++--
src/decoder_xmp.c | 4 ++--
7 files changed, 30 insertions(+), 30 deletions(-)
diff --git a/src/SDL_mixer.c b/src/SDL_mixer.c
index 898e5605..27fc5207 100644
--- a/src/SDL_mixer.c
+++ b/src/SDL_mixer.c
@@ -935,7 +935,7 @@ static const MIX_Decoder *PrepareDecoder(SDL_IOStream *io, MIX_Audio *audio)
if (decoder->init_audio(io, &audio->spec, audio->props, &audio->duration_frames, &audio->decoder_userdata)) {
audio->decoder = decoder;
return decoder;
- } else if (SDL_SeekIO(io, 0, SDL_IO_SEEK_SET) == -1) { // note this seeks to offset 0, because we're using an IoClamp.
+ } else if (SDL_SeekIO(io, 0, SDL_IO_SEEK_SET) < 0) { // note this seeks to offset 0, because we're using an IoClamp.
SDL_SetError("Can't seek in stream to find proper decoder");
return NULL;
}
@@ -1060,7 +1060,7 @@ MIX_Audio *MIX_LoadAudioWithProperties(SDL_PropertiesID props) // lets you spec
audio_userdata = audio->decoder_userdata; // less wordy access to this pointer. :)
// Go back to start of the SDL_IOStream, since we're either precaching, predecoding, or maybe just getting ready to actually play the thing.
- if (io && (SDL_SeekIO(io, 0, SDL_IO_SEEK_SET) == -1)) { // note this seeks to offset 0, because we're using an IoClamp.
+ if (io && (SDL_SeekIO(io, 0, SDL_IO_SEEK_SET) < 0)) { // note this seeks to offset 0, because we're using an IoClamp.
goto failed;
}
@@ -2170,7 +2170,7 @@ static Sint64 GetTrackOptionFramesOrTicks(MIX_Track *track, SDL_PropertiesID opt
} else if (SDL_HasProperty(options, msprop)) {
const Sint64 val = SDL_GetNumberProperty(options, msprop, defval);
Sint64 val_frames = MIX_TrackMSToFrames(track, val);
- if (val_frames == -1) {
+ if (val_frames < 0) {
val_frames = 0;
}
return (val < 0) ? val : val_frames;
@@ -2349,7 +2349,7 @@ bool MIX_StopAllTracks(MIX_Mixer *mixer, Sint64 fade_out_ms)
for (MIX_Track *track = mixer->all_tracks; track != NULL; track = track->next) {
Sint64 fade_out_frames = MIX_TrackMSToFrames(track, fade_out_ms);
- if (fade_out_frames == -1) {
+ if (fade_out_frames < 0) {
fade_out_frames = 0;
}
StopTrack(track, (fade_out_ms > 0) ? fade_out_frames : -1);
@@ -2376,7 +2376,7 @@ bool MIX_StopTag(MIX_Mixer *mixer, const char *tag, Sint64 fade_out_ms)
const size_t total = list->num_tracks;
for (size_t i = 0; i < total; i++) {
Sint64 fade_out_frames = MIX_TrackMSToFrames(list->tracks[i], fade_out_ms);
- if (fade_out_frames == -1) {
+ if (fade_out_frames < 0) {
fade_out_frames = 0;
}
StopTrack(list->tracks[i], (fade_out_ms > 0) ? fade_out_frames : -1);
diff --git a/src/SDL_mixer_metadata_tags.c b/src/SDL_mixer_metadata_tags.c
index 809c841f..fefcd7fe 100644
--- a/src/SDL_mixer_metadata_tags.c
+++ b/src/SDL_mixer_metadata_tags.c
@@ -451,7 +451,7 @@ static bool parse_id3v2(SDL_PropertiesID props, SDL_IOStream *io)
if ((version_major > 2) && ((flags & ID3v2_FLAG_HAS_EXTRA_HEAD) == ID3v2_FLAG_HAS_EXTRA_HEAD)) {
if (SDL_ReadIO(io, buffer + ID3v2_FIELD_EXTRA_HEADER_LENGTH, 4) != 4) {
return false;
- } else if (SDL_SeekIO(io, -4, SDL_IO_SEEK_CUR) == -1) {
+ } else if (SDL_SeekIO(io, -4, SDL_IO_SEEK_CUR) < 0) {
return false;
}
tag_extended_len = id3v2_synchsafe_decode(buffer + ID3v2_FIELD_EXTRA_HEADER_LENGTH); // Length of an extended header
@@ -459,7 +459,7 @@ static bool parse_id3v2(SDL_PropertiesID props, SDL_IOStream *io)
if (tag_extended_len) {
tag_len -= tag_extended_len; // Subtract the size of extended header
- if (SDL_SeekIO(io, tag_extended_len, SDL_IO_SEEK_CUR) == -1) { // Skip extended header and it's size value
+ if (SDL_SeekIO(io, tag_extended_len, SDL_IO_SEEK_CUR) < 0) { // Skip extended header and it's size value
return false;
}
}
@@ -671,7 +671,7 @@ static bool parse_ape(SDL_PropertiesID props, SDL_IOStream *io, Sint64 ape_head_
if (tag_item_size == 0) {
break;
}
- if (SDL_SeekIO(io, cur_tag + tag_item_size + 4, SDL_IO_SEEK_SET) == -1) {
+ if (SDL_SeekIO(io, cur_tag + tag_item_size + 4, SDL_IO_SEEK_SET) < 0) {
return false;
}
}
@@ -716,7 +716,7 @@ static Sint64 get_lyrics3v1_len(SDL_IOStream *io)
return -1;
}
Sint64 len = SDL_min(flen, LYRICS3v1_SEARCH_BUFFER);
- if (SDL_SeekIO(io, -len, SDL_IO_SEEK_END) == -1) {
+ if (SDL_SeekIO(io, -len, SDL_IO_SEEK_END) < 0) {
return -1;
}
@@ -767,8 +767,8 @@ static bool verify_lyrics3v2(const Uint8 *data, size_t length)
static bool is_musicmatch(const Uint8 *data, Sint64 length)
{
- /* From docs/musicmatch.txt in id3lib: https://sourceforge.net/projects/id3lib/
- Overall tag structure:
+ /* From docs/musicmatch.txt in id3lib: https://sourceforge.net/projects/id3lib/
+ Overall tag structure:
+-----------------------------+
| Header |
@@ -820,7 +820,7 @@ static Sint64 get_musicmatch_len(SDL_IOStream *io)
Sint64 len = 0;
Sint32 i, j;
- if (SDL_SeekIO(io, -68, SDL_IO_SEEK_END) == -1) {
+ if (SDL_SeekIO(io, -68, SDL_IO_SEEK_END) < 0) {
return -1;
} else if (SDL_ReadIO(io, buf, 20) != 20) {
return -1;
@@ -842,7 +842,7 @@ static Sint64 get_musicmatch_len(SDL_IOStream *io)
for (i = 0; i < 4; ++i) {
// 48: footer, 20: offsets, 256: version info
len = metasizes[i] + MUSICMATCH_FOOTER_SIZE + MUSICMATCH_OFFSETS_SIZE + MUSICMATCH_VERSION_INFO_SIZE;
- if (SDL_SeekIO(io, -len, SDL_IO_SEEK_END) == -1) {
+ if (SDL_SeekIO(io, -len, SDL_IO_SEEK_END) < 0) {
return -1;
} else if (SDL_ReadIO(io, buf, MUSICMATCH_VERSION_INFO_SIZE) != MUSICMATCH_VERSION_INFO_SIZE) {
return -1;
@@ -866,7 +866,7 @@ static Sint64 get_musicmatch_len(SDL_IOStream *io)
#ifdef MMTAG_PARANOID
// unused section: (4 bytes of 0x00)
- if (SDL_SeekIO(io, -(len + 4), SDL_IO_SEEK_END) == -1) {
+ if (SDL_SeekIO(io, -(len + 4), SDL_IO_SEEK_END) < 0) {
return -1;
} else if (SDL_ReadIO(io, &j, 4) != 4) {
return -1;
@@ -876,7 +876,7 @@ static Sint64 get_musicmatch_len(SDL_IOStream *io)
#endif
len += (version_ofs - imgext_ofs);
- if (SDL_SeekIO(io, -len, SDL_IO_SEEK_END) == -1) {
+ if (SDL_SeekIO(io, -len, SDL_IO_SEEK_END) < 0) {
return -1;
} else if (SDL_ReadIO(io, buf, 8) != 8) {
return -1;
@@ -887,7 +887,7 @@ static Sint64 get_musicmatch_len(SDL_IOStream *io)
// without this, we may land at a wrong place.
if (j + 12 != version_ofs - imgext_ofs) return -1;
// try finding the optional header
- if (SDL_SeekIO(io, -(len + MUSICMATCH_HEADER_SIZE), SDL_IO_SEEK_END) == -1) {
+ if (SDL_SeekIO(io, -(len + MUSICMATCH_HEADER_SIZE), SDL_IO_SEEK_END) < 0) {
return -1;
} else if (SDL_ReadIO(io, buf, MUSICMATCH_HEADER_SIZE) != MUSICMATCH_HEADER_SIZE) {
return -1;
@@ -913,7 +913,7 @@ static Sint64 get_musicmatch_len(SDL_IOStream *io)
static int probe_id3v1(SDL_PropertiesID props, SDL_IOStream *io, Uint8 *buf, int atend, MIX_IoClamp *clamp)
{
- if (SDL_SeekIO(io, -ID3v1_TAG_SIZE, SDL_IO_SEEK_END) == -1) {
+ if (SDL_SeekIO(io, -ID3v1_TAG_SIZE, SDL_IO_SEEK_END) < 0) {
return TAG_INVALID;
} else if (SDL_ReadIO(io, buf, ID3v1_TAG_SIZE) != ID3v1_TAG_SIZE) {
return TAG_INVALID;
@@ -937,7 +937,7 @@ static int probe_id3v1(SDL_PropertiesID props, SDL_IOStream *io, Uint8 *buf, int
static int probe_mmtag(SDL_PropertiesID props, SDL_IOStream *io, Uint8 *buf, MIX_IoClamp *clamp)
{
(void)props; // !!! FIXME: Implement reading tag contents.
- if (SDL_SeekIO(io, -MUSICMATCH_FOOTER_SIZE, SDL_IO_SEEK_END) == -1) {
+ if (SDL_SeekIO(io, -MUSICMATCH_FOOTER_SIZE, SDL_IO_SEEK_END) < 0) {
return TAG_INVALID;
} else if (SDL_ReadIO(io, buf, MUSICMATCH_FOOTER_SIZE) != MUSICMATCH_FOOTER_SIZE) {
return TAG_INVALID;
@@ -955,7 +955,7 @@ static int probe_mmtag(SDL_PropertiesID props, SDL_IOStream *io, Uint8 *buf, MIX
static int probe_apetag(SDL_PropertiesID props, SDL_IOStream *io, Uint8 *buf, MIX_IoClamp *clamp)
{
// APE tag may be at the end: read the footer
- if (SDL_SeekIO(io, -APE_HEADER_SIZE, SDL_IO_SEEK_END) == -1) {
+ if (SDL_SeekIO(io, -APE_HEADER_SIZE, SDL_IO_SEEK_END) < 0) {
return TAG_INVALID;
} else if (SDL_ReadIO(io, buf, APE_HEADER_SIZE) != APE_HEADER_SIZE) {
return TAG_INVALID;
@@ -967,7 +967,7 @@ static int probe_apetag(SDL_PropertiesID props, SDL_IOStream *io, Uint8 *buf, MI
Uint32 v = 0;
const Sint64 len = get_ape_len(buf, &v);
if (v == APE_V2) { // verify header :
- if (SDL_SeekIO(io, -len, SDL_IO_SEEK_END) == -1) {
+ if (SDL_SeekIO(io, -len, SDL_IO_SEEK_END) < 0) {
return TAG_INVALID;
} else if (SDL_ReadIO(io, buf, APE_HEADER_SIZE) != APE_HEADER_SIZE) {
return TAG_INVALID;
@@ -977,7 +977,7 @@ static int probe_apetag(SDL_PropertiesID props, SDL_IOStream *io, Uint8 *buf, MI
retval = TAG_FOUND;
}
} else {
- if (SDL_SeekIO(io, -APE_HEADER_SIZE, SDL_IO_SEEK_END) == -1) {
+ if (SDL_SeekIO(io, -APE_HEADER_SIZE, SDL_IO_SEEK_END) < 0) {
return TAG_INVALID;
} else if (parse_ape(props, io, SDL_TellIO(io), APE_V1)) {
retval = TAG_FOUND;
@@ -991,7 +991,7 @@ static int probe_apetag(SDL_PropertiesID props, SDL_IOStream *io, Uint8 *buf, MI
static int probe_lyrics3(SDL_IOStream *io, Uint8 *buf, MIX_IoClamp *clamp)
{
- if (SDL_SeekIO(io, -LYRICS3_FOOTER_SIZE, SDL_IO_SEEK_END) == -1) {
+ if (SDL_SeekIO(io, -LYRICS3_FOOTER_SIZE, SDL_IO_SEEK_END) < 0) {
return TAG_INVALID;
} else if (SDL_ReadIO(io, buf, LYRICS3_FOOTER_SIZE) != LYRICS3_FOOTER_SIZE) {
return TAG_INVALID;
@@ -1002,7 +1002,7 @@ static int probe_lyrics3(SDL_IOStream *io, Uint8 *buf, MIX_IoClamp *clamp)
const Sint64 len = get_lyrics3v2_len(buf, LYRICS3v2_TAG_SIZE_VALUE);
if (len < LYRICS3_FOOTER_SIZE) {
return TAG_INVALID;
- } else if (SDL_SeekIO(io, -len, SDL_IO_SEEK_END) == -1) {
+ } else if (SDL_SeekIO(io, -len, SDL_IO_SEEK_END) < 0) {
return TAG_INVALID;
} else if (SDL_ReadIO(io, buf, LYRICS3v1_HEAD_SIZE) != LYRICS3v1_HEAD_SIZE) {
return TAG_INVALID;
diff --git a/src/decoder_drflac.c b/src/decoder_drflac.c
index c9291349..292e4420 100644
--- a/src/decoder_drflac.c
+++ b/src/decoder_drflac.c
@@ -145,7 +145,7 @@ static bool SDLCALL DRFLAC_init_audio(SDL_IOStream *io, SDL_AudioSpec *spec, SDL
}
// Go back and do a proper load now to get metadata.
- if (SDL_SeekIO(io, SDL_IO_SEEK_SET, 0) == -1) {
+ if (SDL_SeekIO(io, SDL_IO_SEEK_SET, 0) < 0) {
return false;
}
diff --git a/src/decoder_fluidsynth.c b/src/decoder_fluidsynth.c
index 75457b57..06772a2c 100644
--- a/src/decoder_fluidsynth.c
+++ b/src/decoder_fluidsynth.c
@@ -148,7 +148,7 @@ static bool SDLCALL FLUIDSYNTH_init_audio(SDL_IOStream *io, SDL_AudioSpec *spec,
}
// Go back and do a proper load now to get metadata.
- if (SDL_SeekIO(io, SDL_IO_SEEK_SET, 0) == -1) {
+ if (SDL_SeekIO(io, SDL_IO_SEEK_SET, 0) < 0) {
if (sfio && closesfio) { SDL_CloseIO(sfio); }
return false;
}
diff --git a/src/decoder_gme.c b/src/decoder_gme.c
index e54695f5..07445dca 100644
--- a/src/decoder_gme.c
+++ b/src/decoder_gme.c
@@ -121,7 +121,7 @@ static bool SDLCALL GME_init_audio(SDL_IOStream *io, SDL_AudioSpec *spec, SDL_Pr
*duration_frames = MIX_DURATION_INFINITE;
} else if (info->length >= 0) {
*duration_frames = MIX_MSToFrames(spec->freq, info->length);
- if (*duration_frames == -1) {
+ if (*duration_frames < 0) {
*duration_frames = 0;
}
}
diff --git a/src/decoder_timidity.c b/src/decoder_timidity.c
index d27bc323..2f95aed0 100644
--- a/src/decoder_timidity.c
+++ b/src/decoder_timidity.c
@@ -91,7 +91,7 @@ static bool SDLCALL TIMIDITY_init_audio(SDL_IOStream *io, SDL_AudioSpec *spec, S
}
song_length_in_frames = MIX_MSToFrames(spec->freq, Timidity_GetSongLength(song));
- if (song_length_in_frames == -1) {
+ if (song_length_in_frames < 0) {
song_length_in_frames = 0;
}
Timidity_FreeSong(song);
@@ -142,7 +142,7 @@ static bool SDLCALL TIMIDITY_seek(void *track_userdata, Uint64 frame)
{
TIMIDITY_TrackData *tdata = (TIMIDITY_TrackData *) track_userdata;
Sint64 ticks = MIX_FramesToMS(tdata->freq, frame);
- if (ticks == -1) {
+ if (ticks < 0) {
ticks = 0;
}
Timidity_Seek(tdata->song, (Uint32)ticks); // !!! FIXME: this returns void, what happens if we seek past EOF?
diff --git a/src/decoder_xmp.c b/src/decoder_xmp.c
index ece8b9ef..334c812d 100644
--- a/src/decoder_xmp.c
+++ b/src/decoder_xmp.c
@@ -188,7 +188,7 @@ static bool SDLCALL XMP_init_audio(SDL_IOStream *io, SDL_AudioSpec *spec, SDL_Pr
libxmp.xmp_get_frame_info(ctx, &frame_info);
*duration_frames = MIX_MSToFrames(spec->freq, (Sint64) frame_info.total_time); // closest we can get.
- if (*duration_frames == -1) {
+ if (*duration_frames < 0) {
*duration_frames = 0;
}
@@ -270,7 +270,7 @@ static bool SDLCALL XMP_seek(void *track_userdata, Uint64 frame)
{
XMP_TrackData *tdata = (XMP_TrackData *) track_userdata;
Sint64 ms = MIX_FramesToMS(tdata->freq, (Sint64) frame);
- if (ms == -1) {
+ if (ms < 0) {
ms = 0;
}
const int err = libxmp.xmp_seek_time(tdata->ctx, (int) ms);