guard allocSharedSeq if given seq is empty

This commit is contained in:
Ivan FB 2026-04-24 17:06:12 +02:00
parent 7c03bfd9ac
commit 16e406bdea
No known key found for this signature in database
GPG Key ID: DF0C67A04C543270

View File

@ -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]) =