From 2a6dfd2545b78b91ddb690f30068742212862f81 Mon Sep 17 00:00:00 2001 From: Damian Tarnawski Date: Sat, 23 Aug 2025 16:55:12 +0200 Subject: [PATCH] Avoid overlap issues when correcting memory after resize in _reserve_soa --- base/runtime/core_builtin_soa.odin | 19 ++++++-- tests/core/runtime/test_core_runtime.odin | 58 +++++++++++++++++------ 2 files changed, 58 insertions(+), 19 deletions(-) diff --git a/base/runtime/core_builtin_soa.odin b/base/runtime/core_builtin_soa.odin index 7548f6735..46c767751 100644 --- a/base/runtime/core_builtin_soa.odin +++ b/base/runtime/core_builtin_soa.odin @@ -266,6 +266,12 @@ _reserve_soa :: proc(array: ^$T/#soa[dynamic]$E, capacity: int, zero_memory: boo // from: |x x y y z z _ _ _| // to: |x x _ y y _ z z _| + // move old data to the end of the new allocation to avoid overlap + old_start := uintptr(new_data) + uintptr(new_size - old_size) + mem_copy(rawptr(old_start), old_data, old_size) + + // now: |_ _ _ x x y y z z| + for i in 0..