diff options
author | Miran <narimiran@disroot.org> | 2019-05-20 19:39:38 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2019-05-20 19:39:38 +0200 |
commit | dc6a4b1d43c7980c166e1d3c73a0e96fd26f5eaf (patch) | |
tree | 01ee3242f1a7bd236cf79fd78c3856fbc0a998ce | |
parent | d490bc519a9e04f1c80635124c6869399f9676f0 (diff) | |
download | Nim-dc6a4b1d43c7980c166e1d3c73a0e96fd26f5eaf.tar.gz |
fixes #11049, wrong streams.readBool and streams.peekBool (#11284)
-rw-r--r-- | lib/pure/streams.nim | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/lib/pure/streams.nim b/lib/pure/streams.nim index 83c8c71ec..f1a6a6aeb 100644 --- a/lib/pure/streams.nim +++ b/lib/pure/streams.nim @@ -412,7 +412,11 @@ proc peekChar*(s: Stream): char = if peekData(s, addr(result), sizeof(result)) != 1: result = '\0' proc readBool*(s: Stream): bool = - ## Reads a bool from the stream `s`. Raises `IOError` if an error occurred. + ## Reads a bool from the stream `s`. + ## + ## A bool is one byte long and it is `true` for every non-zero + ## (`0000_0000`) value. + ## Raises `IOError` if an error occurred. runnableExamples: var strm = newStringStream() ## setup for reading data @@ -426,10 +430,16 @@ proc readBool*(s: Stream): bool = doAssertRaises(IOError): discard strm.readBool() strm.close() - read(s, result) + var t: byte + read(s, t) + result = t != 0.byte proc peekBool*(s: Stream): bool = - ## Peeks a bool from the stream `s`. Raises `IOError` if an error occurred. + ## Peeks a bool from the stream `s`. + ## + ## A bool is one byte long and it is `true` for every non-zero + ## (`0000_0000`) value. + ## Raises `IOError` if an error occurred. runnableExamples: var strm = newStringStream() ## setup for reading data @@ -445,7 +455,9 @@ proc peekBool*(s: Stream): bool = doAssert strm.peekBool() == false strm.close() - peek(s, result) + var t: byte + peek(s, t) + result = t != 0.byte proc readInt8*(s: Stream): int8 = ## Reads an int8 from the stream `s`. Raises `IOError` if an error occurred. |