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 From 52a10661a582f82e7db3b279ded4d009f3f1dd62 Mon Sep 17 00:00:00 2001 From: tomohiko okazaki Date: Sun, 16 Jun 2019 23:55:36 +0900 Subject: support nim 0.20.0 --- nimpb/nimpb.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nimpb/nimpb.nim b/nimpb/nimpb.nim index 260b379..3ba3b70 100644 --- a/nimpb/nimpb.nim +++ b/nimpb/nimpb.nim @@ -153,7 +153,7 @@ template fieldNumber*(tag: Tag): int = proc protoReadByte(stream: Stream): byte = ## Read a byte from a stream. - result = readInt8(stream).byte + result = cast[byte](readInt8(stream)) proc protoWriteByte(stream: Stream, b: byte) = ## Write a byte to a stream. -- cgit v1.2.3 From 7a4a9d33a42790181876e393cf894574822e8b09 Mon Sep 17 00:00:00 2001 From: tomohiko okazaki Date: Mon, 17 Jun 2019 00:20:57 +0900 Subject: fix test --- nimpb/nimpb.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nimpb/nimpb.nim b/nimpb/nimpb.nim index 3ba3b70..9ca7742 100644 --- a/nimpb/nimpb.nim +++ b/nimpb/nimpb.nim @@ -118,7 +118,7 @@ proc zigzagEncode*(n: int32): uint32 = let x = cast[uint32](n) let a = cast[int32](x shl 1) let b = -cast[int32](x shr 31) - result = uint32(a xor b) + result = cast[uint32](a xor b) proc zigzagDecode*(n: uint32): int32 = ## ZigZag decode a 32-bit unsigned integer. -- cgit v1.2.3 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