Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

io.readLine adds '\00' char to the end #21273

Closed
inv2004 opened this issue Jan 18, 2023 · 0 comments · Fixed by #21276
Closed

io.readLine adds '\00' char to the end #21273

inv2004 opened this issue Jan 18, 2023 · 0 comments · Fixed by #21276
Assignees

Comments

@inv2004
Copy link
Contributor

inv2004 commented Jan 18, 2023

Description

import strutils

const FILE = "/tmp/failed_file"

let hex = "313632313920313632343720313632353920313632363020313632393020323035363520323037323120323131353020323239393820323331303520323332313020323332343820323332363820"

### buf.len == 78 => error
### if I remove 1 char and buf.len == 77 => everything is ok

writeFile FILE, parseHexStr(hex)

doAssert readFile(FILE).toHex == hex

echo hex

let f = open(FILE)
var s = newString(80)
while f.readLine(s):
  echo s.toHex
  doAssert s.toHex == hex

Nim Version

1.6.10 1.6.8 1.4.8 1.2.8

Current Output

313632313920313632343720313632353920313632363020313632393020323035363520323037323120323131353020323239393820323331303520323332313020323332343820323332363820
31363231392031363234372031363235392031363236302031363239302032303536352032303732312032313135302032323939382032333130352032333231302032333234382032333236382000
/home/u/t.nim(17)        t
/home/u/.choosenim/toolchains/nim-1.6.10/lib/system/assertions.nim(38) failedAssertImpl
/home/u/.choosenim/toolchains/nim-1.6.10/lib/system/assertions.nim(28) raiseAssert
/home/u/.choosenim/toolchains/nim-1.6.10/lib/system/fatal.nim(54) sysFatal
Error: unhandled exception: /home/u/t.nim(17, 12) `s.toHex == hex`  [AssertionDefect]


### Expected Output

```text
313632313920313632343720313632353920313632363020313632393020323035363520323037323120323131353020323239393820323331303520323332313020323332343820323332363820
313632313920313632343720313632353920313632363020313632393020323035363520323037323120323131353020323239393820323331303520323332313020323332343820323332363820


### Possible Solution

_No response_

### Additional Information

_No response_
ringabout added a commit that referenced this issue Jan 19, 2023
Varriount pushed a commit that referenced this issue Jan 25, 2023
narimiran pushed a commit that referenced this issue Jan 27, 2023
)

fixes #21273; io.readLine off by one

(cherry picked from commit c4d3d65)
survivorm pushed a commit to survivorm/Nim that referenced this issue Feb 28, 2023
capocasa pushed a commit to capocasa/Nim that referenced this issue Mar 31, 2023
bung87 pushed a commit to bung87/Nim that referenced this issue Jul 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants