From 74bbb1167f45a9e57d25b2946b0fcd8396dc4c77 Mon Sep 17 00:00:00 2001 From: Jeroen van Rijn Date: Tue, 22 Aug 2023 20:18:54 +0200 Subject: [PATCH] Fix #2763 Fixes #2763 --- core/runtime/core_builtin.odin | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/core/runtime/core_builtin.odin b/core/runtime/core_builtin.odin index 9f2899bcc..6ddd12a5e 100644 --- a/core/runtime/core_builtin.odin +++ b/core/runtime/core_builtin.odin @@ -601,14 +601,15 @@ assign_at_elems :: proc(array: ^$T/[dynamic]$E, index: int, args: ..E, loc := #c @builtin assign_at_elem_string :: proc(array: ^$T/[dynamic]$E/u8, index: int, arg: string, loc := #caller_location) -> (ok: bool, err: Allocator_Error) #no_bounds_check #optional_allocator_error { - if len(args) == 0 { + new_size := index + len(arg) + if len(arg) == 0 { ok = true - } else if index+len(args) < len(array) { - copy(array[index:], args) + } else if new_size < len(array) { + copy(array[index:], arg) ok = true } else { - resize(array, index+1+len(args), loc) or_return - copy(array[index:], args) + resize(array, new_size, loc) or_return + copy(array[index:], arg) ok = true } return