From 17209fd330f7d815133bd5a14130c132c87be57a Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Thu, 12 Dec 2019 14:04:01 +0000 Subject: [PATCH] snd_mp3tag.c: tidy-up return code. add a failsafe for fshandle_t. git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@1660 af15c1b1-3010-417e-b628-4374ebc0bcbd --- Quake/snd_mp3tag.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Quake/snd_mp3tag.c b/Quake/snd_mp3tag.c index 382f810a..3d9bd0b5 100644 --- a/Quake/snd_mp3tag.c +++ b/Quake/snd_mp3tag.c @@ -242,6 +242,9 @@ int mp3_skiptags(snd_stream_t *stream) unsigned char buf[128]; long len; size_t readsize; int rc = -1; + /* failsafe */ + long oldlength = stream->fh.length; + long oldstart = stream->fh.start; readsize = FS_fread(buf, 1, 128, &stream->fh); if (!readsize || FS_ferror(&stream->fh)) goto fail; @@ -330,10 +333,14 @@ int mp3_skiptags(snd_stream_t *stream) } } - rc = 0; + rc = (stream->fh.length > 0)? 0 : -1; fail: + if (rc < 0) { + stream->fh.start = oldstart; + stream->fh.length = oldlength; + } FS_rewind(&stream->fh); - return (stream->fh.length > 0)? rc : -1; + return rc; } #endif /* USE_CODEC_MP3 */