diff options
| author | Feoramund <161657516+Feoramund@users.noreply.github.com> | 2024-09-03 01:14:17 -0400 |
|---|---|---|
| committer | Feoramund <161657516+Feoramund@users.noreply.github.com> | 2024-09-03 01:14:17 -0400 |
| commit | 309953e0f24036145a95248060a33217e15ccb38 (patch) | |
| tree | 11561deb6f157336b593cba72f776946cdc3967a /core/container/small_array/small_array.odin | |
| parent | 71b2527df07a8628093792bbf2a7886bed253a09 (diff) | |
Return false if `Small_Array` can't append multiple elements
Fixes #4177
Diffstat (limited to 'core/container/small_array/small_array.odin')
| -rw-r--r-- | core/container/small_array/small_array.odin | 10 |
1 files changed, 7 insertions, 3 deletions
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 { |