aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--nimpb/nimpb.nim5
1 files changed, 3 insertions, 2 deletions
diff --git a/nimpb/nimpb.nim b/nimpb/nimpb.nim
index 9ca7742..9691650 100644
--- a/nimpb/nimpb.nim
+++ b/nimpb/nimpb.nim
@@ -399,8 +399,9 @@ proc protoWriteBytes*(stream: Stream, bytes: seq[byte], fieldNumber: int) =
proc safeReadStr*(stream: Stream, size: int): string =
result = newString(size)
- if 0 < size and readData(stream, addr(result[0]), size) != size:
- raise newException(IOError, "cannot read from stream")
+ if size > 0:
+ if readData(stream, addr(result[0]), size) != size:
+ raise newException(IOError, "cannot read from stream")
proc protoReadString*(stream: Stream): string =
let size = int(protoReadUInt64(stream))