From 83b41c72d9b35018235df1203c8c3d89676ce945 Mon Sep 17 00:00:00 2001 From: dgelessus Date: Thu, 22 Feb 2024 01:14:07 +0100 Subject: [PATCH] Fix DS::Stream::readLine for files without a trailing newline As is currently the case for some SDL files in the H'uru/Plasma repo. --- streams.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/streams.cpp b/streams.cpp index fbe9542..5def001 100644 --- a/streams.cpp +++ b/streams.cpp @@ -27,12 +27,10 @@ bool DS::Stream::readLine(void* buffer, size_t count) DS_ASSERT(count >= 1); char* outp = reinterpret_cast(buffer); char* endp = outp + count - 1; - bool eof = false; while (outp < endp) { ssize_t nread = readBytes(outp, 1); if (nread == 0) { - eof = true; break; } char c = *outp++; @@ -40,7 +38,8 @@ bool DS::Stream::readLine(void* buffer, size_t count) break; } *outp = 0; - return !eof; + // Signal EOF if the loop terminated without reading anything into the buffer. + return outp != buffer; } ST::string DS::Stream::readString(size_t length, DS::StringType format)