From e84696876a2dade770a99b65c0a6c7076a48b3e4 Mon Sep 17 00:00:00 2001 From: tomohiko okazaki Date: Tue, 25 Jun 2019 15:44:42 +0900 Subject: move conditional check --- nimpb/nimpb.nim | 5 +++-- 1 file 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)) -- cgit v1.2.3