diff options
author | ringabout <43030857+ringabout@users.noreply.github.com> | 2023-01-26 03:56:19 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-25 14:56:19 -0500 |
commit | c4d3d650baa88820dadeafa81ca75b6e495084f2 (patch) | |
tree | 51abc7bbe6aa06965a0ef2e335775ab35e474662 /lib/std/syncio.nim | |
parent | d54a7f078d29445bc79ec5f117a2ceb73761b4c4 (diff) | |
download | Nim-c4d3d650baa88820dadeafa81ca75b6e495084f2.tar.gz |
fixes #21273; fixes an io.readLine off by one bug [backport 1.0] (#21276)
fixes #21273; io.readLine off by one
Diffstat (limited to 'lib/std/syncio.nim')
-rw-r--r-- | lib/std/syncio.nim | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/std/syncio.nim b/lib/std/syncio.nim index 46f113450..83b2d6d13 100644 --- a/lib/std/syncio.nim +++ b/lib/std/syncio.nim @@ -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 |