aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomohiko OKAZAKI <34153037+xcokazaki@users.noreply.github.com>2019-03-12 20:06:13 +0900
committerGitHub <noreply@github.com>2019-03-12 20:06:13 +0900
commit2fef457af5e8f2a804eb4e6293e5d5ada968cf7c (patch)
tree541897306a4906f71d33ec19c787cfe08b7775c2
parenteab5057957ce5c40ec5501f49ea0b02c9f7f9d96 (diff)
downloadnimpb-2fef457af5e8f2a804eb4e6293e5d5ada968cf7c.tar.gz
nimpb-2fef457af5e8f2a804eb4e6293e5d5ada968cf7c.zip
avoid index error if input size is zero (#1)
avoid index error if input size is zero (#1)
-rw-r--r--nimpb/nimpb.nim2
1 files changed, 1 insertions, 1 deletions
diff --git a/nimpb/nimpb.nim b/nimpb/nimpb.nim
index 9933b18..260b379 100644
--- a/nimpb/nimpb.nim
+++ b/nimpb/nimpb.nim
@@ -399,7 +399,7 @@ proc protoWriteBytes*(stream: Stream, bytes: seq[byte], fieldNumber: int) =
proc safeReadStr*(stream: Stream, size: int): string =
result = newString(size)
- if readData(stream, addr(result[0]), size) != size:
+ if 0 < size and readData(stream, addr(result[0]), size) != size:
raise newException(IOError, "cannot read from stream")
proc protoReadString*(stream: Stream): string =