This commit is contained in:
Araq 2018-09-14 11:40:43 +02:00
commit 4ab9953787
3 changed files with 14 additions and 5 deletions

View file

@ -161,7 +161,7 @@ proc readLine(f: File, line: var TaintedString): bool =
var last = cast[ByteAddress](m) - cast[ByteAddress](addr line.string[0])
if last > 0 and line.string[last-1] == '\c':
line.string.setLen(last-1)
return fgetsSuccess
return last > 1 or fgetsSuccess
# We have to distinguish between two possible cases:
# \0\l\0 => line ending in a null character.
# \0\l\l => last line without newline, null was put there by fgets.
@ -169,7 +169,7 @@ proc readLine(f: File, line: var TaintedString): bool =
if last < pos + sp - 1 and line.string[last+1] != '\0':
dec last
line.string.setLen(last)
return fgetsSuccess
return last > 0 or fgetsSuccess
else:
# fgets will have inserted a null byte at the end of the string.
dec sp