From 309953e0f24036145a95248060a33217e15ccb38 Mon Sep 17 00:00:00 2001 From: Feoramund <161657516+Feoramund@users.noreply.github.com> Date: Tue, 3 Sep 2024 01:14:17 -0400 Subject: Return false if `Small_Array` can't append multiple elements Fixes #4177 --- core/container/small_array/small_array.odin | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'core/container/small_array') diff --git a/core/container/small_array/small_array.odin b/core/container/small_array/small_array.odin index b2068469d..77bb21cbc 100644 --- a/core/container/small_array/small_array.odin +++ b/core/container/small_array/small_array.odin @@ -139,9 +139,13 @@ clear :: proc "contextless" (a: ^$A/Small_Array($N, $T)) { resize(a, 0) } -push_back_elems :: proc "contextless" (a: ^$A/Small_Array($N, $T), items: ..T) { - n := copy(a.data[a.len:], items[:]) - a.len += n +push_back_elems :: proc "contextless" (a: ^$A/Small_Array($N, $T), items: ..T) -> bool { + if a.len + builtin.len(items) <= cap(a^) { + n := copy(a.data[a.len:], items[:]) + a.len += n + return true + } + return false } inject_at :: proc "contextless" (a: ^$A/Small_Array($N, $T), item: T, index: int) -> bool #no_bounds_check { -- cgit v1.2.3