fixes zero length input bug in output_stream.append

This commit is contained in:
andri lim 2019-09-03 14:16:42 +07:00 • committed by zah
commit 12250ec3ed
2 changed files with 5 additions and 0 deletions

View file

@ -356,6 +356,7 @@ proc append*(c: var WriteCursor, bytes: openarray[byte]) {.inline.} =
pageRemaining = c.runway pageRemaining = c.runway
inputLen = bytes.len inputLen = bytes.len
if inputLen == 0: return
if inputLen <= pageRemaining: if inputLen <= pageRemaining:
copyMem(c.head, unsafeAddr bytes[0], inputLen) copyMem(c.head, unsafeAddr bytes[0], inputLen)
c.head = shift(c.head, inputLen) c.head = shift(c.head, inputLen)

View file

@ -55,6 +55,10 @@ suite "output stream":
test "no appends produce an empty output": test "no appends produce an empty output":
checkOutputsMatch() checkOutputsMatch()
test "append zero length slice":
output ""
checkOutputsMatch()
test "string output": test "string output":
for i in 0 .. 1: for i in 0 .. 1:
output $i output $i