shithub: choc

Download patch

ref: 51d5fc29b0b7cda79b593e499ff67a5960f6055b
parent: ec72b141f47cd1a5b061f9bc87c1a02e2722be59
author: Fabian Greffrath <fabian@greffrath.com>
date: Tue Apr 21 03:46:16 EDT 2015

deh: fix parsing of last lines in files without newline at EOF

Chocolate Doom fails to properly parse the last line in DEHACKED files
that are missing a newline character at the end of the file (which
might have been a common sickness to DOS editors).

This is, because DEH_GetChar() returns -1 at EOF and DEH_ReadLine() in
turn immediately returns NULL if the result of (DEH_GetChar() < 0),
regardless of the content of the readbuffer. It only returns a pointer
to the content of the readbuffer if DEH_GetChar() returns '\n' which
is, however, impossible if there is no such character before the file
ends.

Now DEH_ReadLine() only returns NULL if the readbuffer is empty at the
end of the file and returns a valid pointer else.

Fixes #531

--- a/src/deh_io.c
+++ b/src/deh_io.c
@@ -235,7 +235,7 @@
     {
         c = DEH_GetChar(context);
 
-        if (c < 0)
+        if (c < 0 && pos == 0)
         {
             // end of file
 
@@ -273,7 +273,7 @@
 
         // blanks before the backslash are included in the string
         // but indentation after the linefeed is not
-        if (escaped && isspace(c) && c != '\n')
+        if (escaped && c >= 0 && isspace(c) && c != '\n')
         {
             continue;
         }
@@ -282,7 +282,7 @@
             escaped = false;
         }
 
-        if (c == '\n')
+        if (c == '\n' || c < 0)
         {
             // end of line: a full line has been read