Skip to content

Commit f90c7ca

Browse files
mywave82frno7
authored andcommitted
sndh: Fix unordered substring offsets
1 parent 29fc843 commit f90c7ca

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

include/psgplay/sndh.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ struct sndh_cursor {
292292
bool (*read)(struct sndh_cursor *cursor);
293293
size_t start;
294294
size_t bound;
295+
size_t end;
295296
} subtag;
296297

297298
bool hdns;

lib/psgplay/sndh.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,15 @@ static bool sndh_substrings_subtag(struct sndh_cursor *cursor)
168168
if (!e)
169169
return false;
170170

171+
if (e > cursor->subtag.end)
172+
cursor->subtag.end = e; /* Keep end of last substring */
173+
171174
tag_update(&c[o], 0, cursor);
172175

173176
cursor->offset += 2;
174177

175178
if (cursor->offset == cursor->subtag.bound)
176-
cursor->offset = cursor->subtag.bound = e;
179+
cursor->offset = cursor->subtag.bound = cursor->subtag.end;
177180

178181
return true;
179182
}
@@ -189,6 +192,7 @@ static bool sndh_substrings(struct sndh_cursor *cursor)
189192

190193
cursor->subtag.start = cursor->offset - strlen(cursor->tag->name);
191194
cursor->subtag.bound = cursor->offset + cursor->subtunes * 2;
195+
cursor->subtag.end = 0;
192196

193197
if (cursor->bound < cursor->subtag.bound) {
194198
diag_error(cursor, "tag %s too short", cursor->tag->name);

0 commit comments

Comments
 (0)