From 16e406bdea57304b5c1e313adb64aafee5ea496a Mon Sep 17 00:00:00 2001 From: Ivan FB Date: Fri, 24 Apr 2026 17:06:12 +0200 Subject: [PATCH] guard allocSharedSeq if given seq is empty --- ffi/alloc.nim | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ffi/alloc.nim b/ffi/alloc.nim index 69c5340..a841a8f 100644 --- a/ffi/alloc.nim +++ b/ffi/alloc.nim @@ -25,8 +25,11 @@ proc alloc*(str: string): cstring = proc allocSharedSeq*[T](s: seq[T]): SharedSeq[T] = let data = allocShared(sizeof(T) * s.len) - if s.len != 0: - copyMem(data, unsafeAddr s[0], sizeof(T) * s.len) + + if s.len == 0: + return (cast[ptr UncheckedArray[T]](nil), 0) + + copyMem(data, unsafeAddr s[0], sizeof(T) * s.len) return (cast[ptr UncheckedArray[T]](data), s.len) proc deallocSharedSeq*[T](s: var SharedSeq[T]) =