Skip to content

Commit

Permalink
Code that doesn't special case Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Yu-Vitaqua-fer-Chronos committed Dec 3, 2023
1 parent 3f927be commit fbfa897
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/modernnet/buffer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,10 @@ func readVarNum*[R: int32 | int64](b: Buffer): R {.raises: [MnEndOfBufferError,
func readString*(b: Buffer): string {.raises: [MnEndOfBufferError, MnPacketParsingError].} =
## Reads a string from a buffer
let length = b.readVarNum[:int32]()
when defined(windows):
## Related to nim itself bug on windows, without this line result can be wrong (example in: echo result)...
let stringAddress {.used.} = b.buf[b.pos..<(b.pos+length)]
result = cast[string](b.buf[b.pos..<(b.pos+length)])
else:
result = cast[string](b.buf[b.pos..<(b.pos+length)])
result.setLen(length)

let data = b.buf[b.pos..<(b.pos+length)]
result = cast[string](data)

b.pos += length

Expand Down

0 comments on commit fbfa897

Please sign in to comment.