sdl12-compat: cdrom: Fix end offset calulcation in SDL_CDPlay

From 9ff63b728f2cb0f844edccf9fcc2f99c0d6b23e3 Mon Sep 17 00:00:00 2001
From: David Gow <[EMAIL REDACTED]>
Date: Sat, 8 Oct 2022 21:22:03 +0800
Subject: [PATCH] cdrom: Fix end offset calulcation in SDL_CDPlay

We were accidentally using the frame number instead of the track number
to lookup a track, which not only resulted in playback cutting off in
the middle of tracks, but also probably accessed a bunch of invalid
memory.
---
 src/SDL12_compat.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/SDL12_compat.c b/src/SDL12_compat.c
index a7dfa5c30..a49b1f9b1 100644
--- a/src/SDL12_compat.c
+++ b/src/SDL12_compat.c
@@ -8701,12 +8701,12 @@ SDL_CDPlay(SDL12_CD *cdrom, int start, int length)
 
     start_frame = start - cdrom->track[start_track].offset;
 
-    if (remain < (cdrom->track[start_frame].length - start_frame)) {
+    if (remain < (cdrom->track[start_track].length - start_frame)) {
         ntracks = 0;
         nframes = remain;
         remain = 0;
     } else {
-        remain -= (cdrom->track[start_frame].length - start_frame);
+        remain -= (cdrom->track[start_track].length - start_frame);
         for (i = start_track + 1; i < cdrom->numtracks; i++) {
             if (remain < cdrom->track[i].length) {
                 ntracks = i - start_track;