diff options
| author | tomohiko okazaki <tomohiko.okazaki@xcompass.com> | 2019-06-25 15:44:42 +0900 |
|---|---|---|
| committer | tomohiko okazaki <tomohiko.okazaki@xcompass.com> | 2019-06-25 15:44:42 +0900 |
| commit | e84696876a2dade770a99b65c0a6c7076a48b3e4 (patch) | |
| tree | 87a7def68fd116ad8788b1f1c5c49ea4d6ffa1ba | |
| parent | 7a4a9d33a42790181876e393cf894574822e8b09 (diff) | |
| download | nimpb-e84696876a2dade770a99b65c0a6c7076a48b3e4.tar.gz nimpb-e84696876a2dade770a99b65c0a6c7076a48b3e4.zip | |
move conditional check
| -rw-r--r-- | nimpb/nimpb.nim | 5 |
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)) |
