From e238632e57fc35d5da2902bc6b037e3a452447db Mon Sep 17 00:00:00 2001 From: Dustin Brody Date: Thu, 17 Mar 2022 07:39:39 +0000 Subject: [PATCH 1/4] don't even notionally access element 0 of 0-length openArray --- faststreams/inputs.nim | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/faststreams/inputs.nim b/faststreams/inputs.nim index 5dc051b..ea78d8a 100644 --- a/faststreams/inputs.nim +++ b/faststreams/inputs.nim @@ -442,7 +442,11 @@ proc fileInput*(filename: string, return fileInput(file, offset, pageSize) proc unsafeMemoryInput*(mem: openArray[byte]): InputStreamHandle = - let head = unsafeAddr mem[0] + let head = + if mem.len > 0: + unsafeAddr mem[0] + else: + default(ptr byte) makeHandle InputStream( span: PageSpan( From 07184af9651514bfcd60741be3dd69c8384d428d Mon Sep 17 00:00:00 2001 From: Dustin Brody Date: Thu, 17 Mar 2022 08:39:45 +0000 Subject: [PATCH 2/4] use ptr byte cast --- faststreams/inputs.nim | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/faststreams/inputs.nim b/faststreams/inputs.nim index ea78d8a..e646338 100644 --- a/faststreams/inputs.nim +++ b/faststreams/inputs.nim @@ -442,11 +442,7 @@ proc fileInput*(filename: string, return fileInput(file, offset, pageSize) proc unsafeMemoryInput*(mem: openArray[byte]): InputStreamHandle = - let head = - if mem.len > 0: - unsafeAddr mem[0] - else: - default(ptr byte) + let head = cast[ptr byte](mem) makeHandle InputStream( span: PageSpan( From 38c83660fa3eaac1c5e049498721e71efdbb97e7 Mon Sep 17 00:00:00 2001 From: Dustin Brody Date: Thu, 17 Mar 2022 09:31:24 +0000 Subject: [PATCH 3/4] consumedTo becomes negative to indicate delayed writes, so use type that allows for that --- faststreams/buffers.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/faststreams/buffers.nim b/faststreams/buffers.nim index 267616d..d7747b7 100644 --- a/faststreams/buffers.nim +++ b/faststreams/buffers.nim @@ -11,7 +11,7 @@ type startAddr*, endAddr*: ptr byte Page* = object - consumedTo*: Natural + consumedTo*: int writtenTo*: Natural data*: ref string From 9a4a25e3e03a32eaefa57e70d2e08bc24154f894 Mon Sep 17 00:00:00 2001 From: Dustin Brody Date: Thu, 17 Mar 2022 21:13:32 +0000 Subject: [PATCH 4/4] fix 32-bit timer overflow and typo in base64 error message --- tests/base64.nim | 2 +- tests/test_pipelines.nim | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/base64.nim b/tests/base64.nim index 3bd9c88..74b310a 100644 --- a/tests/base64.nim +++ b/tests/base64.nim @@ -121,7 +121,7 @@ proc base64decode*(i: InputStream, o: OutputStream) {.fsMultiSync.} = inputChar(d) outputChar(c shl 6 or d shr 0) elif i.readable: - raise newException(ValueError, "The input stream has insufficient nymber of bytes for base64 decoding") + raise newException(ValueError, "The input stream has insufficient number of bytes for base64 decoding") close o diff --git a/tests/test_pipelines.nim b/tests/test_pipelines.nim index 6952a9e..5640616 100644 --- a/tests/test_pipelines.nim +++ b/tests/test_pipelines.nim @@ -41,7 +41,7 @@ when fsAsyncSupport: template timeit(timerVar: var Nanos, code: untyped) = let t0 = getTicks() code - timerVar = int(getTicks() - t0) div 1000000 + timerVar = int64(getTicks() - t0) div 1000000 proc getOutput(sp: AsyncInputStream, T: type string): Future[string] {.async.} = # this proc is a quick hack to let the test pass