Skip to content

Commit 331080b

Browse files
Sackzementicculus
authored andcommitted
After calling a conversion function, set the value to 0 on error(-1)
Necessary so that the behavior is the same as when the return value was 0 on error.
1 parent 2d200ab commit 331080b

File tree

5 files changed

+41
-10
lines changed

5 files changed

+41
-10
lines changed

src/SDL_mixer.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1950,7 +1950,11 @@ static Sint64 GetTrackOptionFramesOrTicks(MIX_Track *track, SDL_PropertiesID opt
19501950
return SDL_GetNumberProperty(options, framesprop, defval);
19511951
} else if (SDL_HasProperty(options, msprop)) {
19521952
const Sint64 val = SDL_GetNumberProperty(options, msprop, defval);
1953-
return (val < 0) ? val : MIX_TrackMSToFrames(track, val);
1953+
Sint64 val_frames = MIX_TrackMSToFrames(track, val);
1954+
if (val_frames == -1) {
1955+
val_frames = 0;
1956+
}
1957+
return (val < 0) ? val : val_frames;
19541958
}
19551959
return defval;
19561960
}
@@ -2118,7 +2122,11 @@ bool MIX_StopAllTracks(MIX_Mixer *mixer, Sint64 fade_out_ms)
21182122
LockMixer(mixer); // lock the mixer so all tracks stop at the same time.
21192123

21202124
for (MIX_Track *track = mixer->all_tracks; track != NULL; track = track->next) {
2121-
StopTrack(track, (fade_out_ms > 0) ? MIX_TrackMSToFrames(track, fade_out_ms) : -1);
2125+
Sint64 fade_out_frames = MIX_TrackMSToFrames(track, fade_out_ms);
2126+
if (fade_out_frames == -1) {
2127+
fade_out_frames = 0;
2128+
}
2129+
StopTrack(track, (fade_out_ms > 0) ? fade_out_frames : -1);
21222130
}
21232131

21242132
UnlockMixer(mixer);
@@ -2141,7 +2149,11 @@ bool MIX_StopTag(MIX_Mixer *mixer, const char *tag, Sint64 fade_out_ms)
21412149

21422150
const size_t total = list->num_tracks;
21432151
for (size_t i = 0; i < total; i++) {
2144-
StopTrack(list->tracks[i], (fade_out_ms > 0) ? MIX_TrackMSToFrames(list->tracks[i], fade_out_ms) : -1);
2152+
Sint64 fade_out_frames = MIX_TrackMSToFrames(list->tracks[i], fade_out_ms);
2153+
if (fade_out_frames == -1) {
2154+
fade_out_frames = 0;
2155+
}
2156+
StopTrack(list->tracks[i], (fade_out_ms > 0) ? fade_out_frames : -1);
21452157
}
21462158

21472159
SDL_UnlockRWLock(list->rwlock);

src/decoder_fluidsynth.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,10 +338,13 @@ static bool SDLCALL FLUIDSYNTH_seek(void *track_userdata, Uint64 frame)
338338
return SDL_Unsupported();
339339
#else
340340
FLUIDSYNTH_TrackData *tdata = (FLUIDSYNTH_TrackData *) track_userdata;
341-
const int ticks = (int) MIX_FramesToMS(tdata->freq, frame);
341+
Sint64 ticks = MIX_FramesToMS(tdata->freq, frame);
342+
if (ticks == -1) {
343+
ticks = 0;
344+
}
342345

343346
// !!! FIXME: docs say this will fail if a seek was requested and then a second seek happens before we play more of the midi file, since the first seek will still be in progress.
344-
return (fluidsynth.fluid_player_seek(tdata->player, ticks) == FLUID_OK);
347+
return (fluidsynth.fluid_player_seek(tdata->player, (int)ticks) == FLUID_OK);
345348
#endif
346349
}
347350

src/decoder_gme.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ static bool SDLCALL GME_init_audio(SDL_IOStream *io, SDL_AudioSpec *spec, SDL_Pr
111111
if ((info->intro_length >= 0) && (info->loop_length > 0)) {
112112
*duration_frames = MIX_DURATION_INFINITE;
113113
} else if (info->length >= 0) {
114-
*duration_frames = (Sint64) MIX_MSToFrames(spec->freq, info->length);
114+
*duration_frames = MIX_MSToFrames(spec->freq, info->length);
115+
if (*duration_frames == -1) {
116+
*duration_frames = 0;
117+
}
115118
}
116119

117120
gme.gme_free_info(info);

src/decoder_timidity.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ static bool SDLCALL TIMIDITY_init_audio(SDL_IOStream *io, SDL_AudioSpec *spec, S
9191
}
9292

9393
song_length_in_frames = MIX_MSToFrames(spec->freq, Timidity_GetSongLength(song));
94+
if (song_length_in_frames == -1) {
95+
song_length_in_frames = 0;
96+
}
9497
Timidity_FreeSong(song);
9598

9699
*duration_frames = song_length_in_frames;
@@ -138,8 +141,11 @@ static bool SDLCALL TIMIDITY_decode(void *track_userdata, SDL_AudioStream *strea
138141
static bool SDLCALL TIMIDITY_seek(void *track_userdata, Uint64 frame)
139142
{
140143
TIMIDITY_TrackData *tdata = (TIMIDITY_TrackData *) track_userdata;
141-
const Uint32 ticks = (Uint32) MIX_FramesToMS(tdata->freq, frame);
142-
Timidity_Seek(tdata->song, ticks); // !!! FIXME: this returns void, what happens if we seek past EOF?
144+
Sint64 ticks = MIX_FramesToMS(tdata->freq, frame);
145+
if (ticks == -1) {
146+
ticks = 0;
147+
}
148+
Timidity_Seek(tdata->song, (Uint32)ticks); // !!! FIXME: this returns void, what happens if we seek past EOF?
143149
return true;
144150
}
145151

src/decoder_xmp.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,10 @@ static bool SDLCALL XMP_init_audio(SDL_IOStream *io, SDL_AudioSpec *spec, SDL_Pr
177177
struct xmp_frame_info frame_info;
178178
libxmp.xmp_get_frame_info(ctx, &frame_info);
179179

180-
*duration_frames = MIX_MSToFrames(spec->freq, (Uint64) frame_info.total_time); // closest we can get.
180+
*duration_frames = MIX_MSToFrames(spec->freq, (Sint64) frame_info.total_time); // closest we can get.
181+
if (*duration_frames == -1) {
182+
*duration_frames = 0;
183+
}
181184

182185
libxmp.xmp_stop_module(ctx);
183186
libxmp.xmp_end_player(ctx);
@@ -256,7 +259,11 @@ static bool SDLCALL XMP_decode(void *track_userdata, SDL_AudioStream *stream)
256259
static bool SDLCALL XMP_seek(void *track_userdata, Uint64 frame)
257260
{
258261
XMP_TrackData *tdata = (XMP_TrackData *) track_userdata;
259-
const int err = libxmp.xmp_seek_time(tdata->ctx, (int) MIX_FramesToMS(tdata->freq, frame));
262+
Sint64 ms = MIX_FramesToMS(tdata->freq, (Sint64) frame);
263+
if (ms == -1) {
264+
ms = 0;
265+
}
266+
const int err = libxmp.xmp_seek_time(tdata->ctx, (int) ms);
260267
return err ? SetLibXmpError("xmp_seek_time", err) : true;
261268
}
262269

0 commit comments

Comments
 (0)