From 93e6b9bc703af8f57f0ebd0d8686a892c0fa67e4 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sun, 20 Oct 2019 14:47:02 +0200 Subject: [PATCH] More tweaks to cue sheet loading code - feof(fp) is now checked for before fgets() is called, should allow final lines without a trailing line break to be parsed. --- src/cdrom/cdrom_dosbox.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/cdrom/cdrom_dosbox.cpp b/src/cdrom/cdrom_dosbox.cpp index 6dc53cad3..daca0e37e 100644 --- a/src/cdrom/cdrom_dosbox.cpp +++ b/src/cdrom/cdrom_dosbox.cpp @@ -609,16 +609,18 @@ CDROM_Interface_Image::CueLoadSheet(const wchar_t *cuefile) char *line = buf; /* Read a line from the cuesheet file. */ - if (fgets(buf, sizeof(buf), fp) == NULL || ferror(fp) || feof(fp)) + if (feof(fp) || fgets(buf, sizeof(buf), fp) == NULL || ferror(fp)) break; /* Do two iterations to make sure to nuke even if it's \r\n or \n\r, but do checks to make sure we're not nuking other bytes. */ for (i = 0; i < 2; i++) { - if (buf[strlen(buf) - 1] == '\n') - buf[strlen(buf) - 1] = '\0'; /* nuke trailing newline */ - else if (buf[strlen(buf) - 1] == '\r') - buf[strlen(buf) - 1] = '\0'; /* nuke trailing newline */ + if (strlen(buf) > 0) { + if (buf[strlen(buf) - 1] == '\n') + buf[strlen(buf) - 1] = '\0'; /* nuke trailing newline */ + else if (buf[strlen(buf) - 1] == '\r') + buf[strlen(buf) - 1] = '\0'; /* nuke trailing newline */ + } } string command;