From 12250ec3edf4e91fe2ef98556dd27f65012db524 Mon Sep 17 00:00:00 2001 From: andri lim Date: Tue, 3 Sep 2019 14:16:42 +0700 Subject: [PATCH] fixes zero length input bug in output_stream.append --- faststreams/output_stream.nim | 1 + tests/test_output_stream.nim | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/faststreams/output_stream.nim b/faststreams/output_stream.nim index a3193fb..5fd8dae 100644 --- a/faststreams/output_stream.nim +++ b/faststreams/output_stream.nim @@ -356,6 +356,7 @@ proc append*(c: var WriteCursor, bytes: openarray[byte]) {.inline.} = pageRemaining = c.runway inputLen = bytes.len + if inputLen == 0: return if inputLen <= pageRemaining: copyMem(c.head, unsafeAddr bytes[0], inputLen) c.head = shift(c.head, inputLen) diff --git a/tests/test_output_stream.nim b/tests/test_output_stream.nim index 26f02f1..90f17a2 100644 --- a/tests/test_output_stream.nim +++ b/tests/test_output_stream.nim @@ -55,6 +55,10 @@ suite "output stream": test "no appends produce an empty output": checkOutputsMatch() + test "append zero length slice": + output "" + checkOutputsMatch() + test "string output": for i in 0 .. 1: output $i