From 06e516e70994ae28fd6d1f766a99dac09578c2bb Mon Sep 17 00:00:00 2001 From: Yuriy Glukhov Date: Mon, 6 Aug 2018 18:32:42 +0300 Subject: [PATCH] Fixed empty string deserialization --- rlp.nim | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/rlp.nim b/rlp.nim index 54b627b..0c6fc91 100644 --- a/rlp.nim +++ b/rlp.nim @@ -230,7 +230,7 @@ proc toBytes*(self: Rlp): BytesRange = ibegin = position + payloadOffset iend = ibegin + payloadLen - 1 - result = bytes.slice(ibegin, iend) + result = bytes.slice(ibegin, iend) proc currentElemEnd(self: Rlp): int = assert hasData() @@ -329,8 +329,9 @@ proc readImpl[E](rlp: var Rlp, T: type seq[E]): T = when E is (byte or char): var bytes = rlp.toBytes - result = newSeq[byte](bytes.len) - copyMem(addr result[0], bytes.baseAddr, bytes.len) + if bytes.len != 0: + result = newSeq[byte](bytes.len) + copyMem(addr result[0], bytes.baseAddr, bytes.len) rlp.skipElem else: if not rlp.isList: