From ae96b276c144982f1ca917bec8ef90de49e5d23a Mon Sep 17 00:00:00 2001 From: Feoramund <161657516+Feoramund@users.noreply.github.com> Date: Sat, 14 Jun 2025 12:00:17 -0400 Subject: [PATCH] mem: Check if `alignment` matches on `Stack_Allocator` resize --- core/mem/allocators.odin | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/core/mem/allocators.odin b/core/mem/allocators.odin index 6b8f97ec6..dfb76b101 100644 --- a/core/mem/allocators.odin +++ b/core/mem/allocators.odin @@ -1137,6 +1137,16 @@ stack_resize_bytes_non_zeroed :: proc( // NOTE(bill): Allow double frees return nil, nil } + if uintptr(old_memory) & uintptr(alignment-1) != 0 { + // A different alignment has been requested and the current address + // does not satisfy it. + data, err := stack_alloc_bytes_non_zeroed(s, size, alignment, loc) + if err == nil { + runtime.copy(data, byte_slice(old_memory, old_size)) + sanitizer.address_poison(old_memory) + } + return data, err + } if old_size == size { return byte_slice(old_memory, size), nil }