From d0127174eff2e46746ef066e6c09a82f6802480d Mon Sep 17 00:00:00 2001
From: pionere <[EMAIL REDACTED]>
Date: Sat, 25 Dec 2021 10:30:40 +0100
Subject: [PATCH] fix handling of SDL_RWseek in music_wav.c - fix 'improve
ParseFMT': SDL_RWseek returns -1 not 0 on error - propagate error when
SDL_RWseek returns -1 - always check the result of SDL_RWseek againts -1
---
src/codecs/music_wav.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/src/codecs/music_wav.c b/src/codecs/music_wav.c
index 4b9b7220..1e3569ee 100644
--- a/src/codecs/music_wav.c
+++ b/src/codecs/music_wav.c
@@ -243,7 +243,7 @@ static int WAV_Play(void *context, int play_count)
loop->current_play_count = loop->initial_play_count;
}
music->play_count = play_count;
- if (SDL_RWseek(music->src, music->start, RW_SEEK_SET) < 0) {
+ if (SDL_RWseek(music->src, music->start, RW_SEEK_SET) == -1) {
return -1;
}
return 0;
@@ -547,7 +547,8 @@ static int WAV_GetSome(void *context, void *data, int bytes, SDL_bool *done)
if (loop->current_play_count > 0) {
--loop->current_play_count;
}
- SDL_RWseek(music->src, loop_start, RW_SEEK_SET);
+ if (SDL_RWseek(music->src, loop_start, RW_SEEK_SET) == -1)
+ return -1;
looped = SDL_TRUE;
}
}
@@ -586,7 +587,8 @@ static int WAV_Seek(void *context, double position)
destpos -= dest_offset % sample_size;
if (destpos > music->stop)
return -1;
- SDL_RWseek(music->src, destpos, RW_SEEK_SET);
+ if (SDL_RWseek(music->src, destpos, RW_SEEK_SET) == -1)
+ return -1;
return 0;
}
@@ -651,7 +653,7 @@ static SDL_bool ParseFMT(WAV_Music *wave, Uint32 chunk_length)
return SDL_FALSE;
}
chunk_length -= size;
- if (chunk_length != 0 && !SDL_RWseek(wave->src, chunk_length, RW_SEEK_CUR)) {
+ if (chunk_length != 0 && SDL_RWseek(wave->src, chunk_length, RW_SEEK_CUR) == -1) {
Mix_SetError("Couldn't read %d bytes from WAV file", chunk_length);
return SDL_FALSE;
}
@@ -748,7 +750,8 @@ static SDL_bool ParseDATA(WAV_Music *wave, Uint32 chunk_length)
{
wave->start = SDL_RWtell(wave->src);
wave->stop = wave->start + chunk_length;
- SDL_RWseek(wave->src, chunk_length, RW_SEEK_CUR);
+ if (SDL_RWseek(wave->src, chunk_length, RW_SEEK_CUR) == -1)
+ return SDL_FALSE;
return SDL_TRUE;
}
@@ -916,7 +919,8 @@ static SDL_bool LoadWAVMusic(WAV_Music *wave)
return SDL_FALSE;
break;
default:
- SDL_RWseek(src, chunk_length, RW_SEEK_CUR);
+ if (SDL_RWseek(src, chunk_length, RW_SEEK_CUR) == -1)
+ return SDL_FALSE;
break;
}
}