From c5dc2790aa80cf71d2db7eac668fabd8b2e553a6 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Tue, 11 Aug 2026 07:01:24 +0300
Subject: [PATCH] readsbk.c: make READID and READB macros into functions.
also change the READ?? helpers to return 0 on success.
---
src/timidity/readsbk.c | 27 ++++++++++++++++++++-------
1 file changed, 20 insertions(+), 7 deletions(-)
diff --git a/src/timidity/readsbk.c b/src/timidity/readsbk.c
index 1fd61b53..aa1246ff 100644
--- a/src/timidity/readsbk.c
+++ b/src/timidity/readsbk.c
@@ -25,23 +25,38 @@
static int READCHUNK(tchunk *vp, SDL_IOStream *io)
{
- if (SDL_ReadIO(io, vp, 8) != 8) return -1;
+ if (SDL_ReadIO(io, vp, 8) != 8) {
+ SDL_memset(vp, 0, sizeof(*vp));
+ return -1;
+ }
vp->size = SDL_Swap32LE(vp->size);
- return 1;
+ return 0;
+}
+
+static int READID(char var[4], SDL_IOStream *io)
+{
+ if ((SDL_ReadIO(io, var, 4)) != 4) return -1;
+ return 0;
}
static int READDW(Sint32 *vp, SDL_IOStream *io)
{
if (SDL_ReadIO(io, vp, 4) != 4) return -1;
*vp = SDL_Swap32LE(*vp);
- return 1;
+ return 0;
}
static int READW(Uint16 *vp, SDL_IOStream *io)
{
if (SDL_ReadIO(io, vp, 2) != 2) return -1;
*vp = SDL_Swap16LE(*vp);
- return 1;
+ return 0;
+}
+
+static int READB(Uint8 *vp, SDL_IOStream *io)
+{
+ if (SDL_ReadIO(io, vp, 1) != 1) return -1;
+ return 0;
}
static int READSTR(char *str, SDL_IOStream *io)
@@ -53,11 +68,9 @@ static int READSTR(char *str, SDL_IOStream *io)
while (n > 0 && str[n - 1] == ' ')
n--;
str[n] = '\0';
- return n;
+ return 0;
}
-#define READID(var,io) SDL_ReadIO(io, var, 4)
-#define READB(var,io) SDL_ReadIO(io, var, 1)
#define SKIPB(io) SDL_SeekIO(io, 1, SDL_IO_SEEK_CUR);
#define SKIPW(io) SDL_SeekIO(io, 2, SDL_IO_SEEK_CUR);
#define SKIPDW(io) SDL_SeekIO(io, 4, SDL_IO_SEEK_CUR);