diff options
author | Fabian Greffrath | 2015-04-21 07:46:16 +0200 |
---|---|---|
committer | Fabian Greffrath | 2015-04-21 07:46:16 +0200 |
commit | 51d5fc29b0b7cda79b593e499ff67a5960f6055b (patch) | |
tree | 93a4db9fd0c9824c9587a8799265b39bfe2a0968 /src | |
parent | ec72b141f47cd1a5b061f9bc87c1a02e2722be59 (diff) | |
download | chocolate-doom-51d5fc29b0b7cda79b593e499ff67a5960f6055b.tar.gz chocolate-doom-51d5fc29b0b7cda79b593e499ff67a5960f6055b.tar.bz2 chocolate-doom-51d5fc29b0b7cda79b593e499ff67a5960f6055b.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/deh_io.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/deh_io.c b/src/deh_io.c index c5e81b0a..e8beb438 100644 --- a/src/deh_io.c +++ b/src/deh_io.c @@ -235,7 +235,7 @@ char *DEH_ReadLine(deh_context_t *context, boolean extended) { c = DEH_GetChar(context); - if (c < 0) + if (c < 0 && pos == 0) { // end of file @@ -273,7 +273,7 @@ char *DEH_ReadLine(deh_context_t *context, boolean extended) // 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 @@ char *DEH_ReadLine(deh_context_t *context, boolean extended) escaped = false; } - if (c == '\n') + if (c == '\n' || c < 0) { // end of line: a full line has been read |