mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-29 19:57:58 +00:00
fixes #21273; io.readLine off by one
This commit is contained in:
@@ -484,11 +484,12 @@ proc readLine*(f: File, line: var string): bool {.tags: [ReadIOEffect],
|
||||
if last > 0 and line[last-1] == '\c':
|
||||
line.setLen(last-1)
|
||||
return last > 1 or fgetsSuccess
|
||||
# We have to distinguish between two possible cases:
|
||||
elif last > 0 and line[last-1] == '\0':
|
||||
# We have to distinguish among three possible cases:
|
||||
# \0\l\0 => line ending in a null character.
|
||||
# \0\l\l => last line without newline, null was put there by fgets.
|
||||
elif last > 0 and line[last-1] == '\0':
|
||||
if last < pos + sp - 1 and line[last+1] != '\0':
|
||||
# \0\l => last line without newline, null was put there by fgets.
|
||||
if last >= pos + sp - 1 or line[last+1] != '\0': # bug #21273
|
||||
dec last
|
||||
line.setLen(last)
|
||||
return last > 0 or fgetsSuccess
|
||||
|
||||
Reference in New Issue
Block a user