From 2fef457af5e8f2a804eb4e6293e5d5ada968cf7c Mon Sep 17 00:00:00 2001 From: Tomohiko OKAZAKI <34153037+xcokazaki@users.noreply.github.com> Date: Tue, 12 Mar 2019 20:06:13 +0900 Subject: avoid index error if input size is zero (#1) avoid index error if input size is zero (#1) --- nimpb/nimpb.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 = -- cgit v1.2.3