[mem]: Fix handling of default resize to check alignment

This commit is contained in:
flysand7
2024-09-11 08:00:27 +11:00
parent fdd4882568
commit f16ed256ea
3 changed files with 19 additions and 5 deletions
+1 -1
View File
@@ -1096,7 +1096,7 @@ _default_resize_bytes_align :: #force_inline proc(
err := free_bytes(old_data, allocator, loc)
return nil, err
}
if new_size == old_size {
if new_size == old_size && is_aligned(old_memory, alignment) {
return old_data, .None
}
new_memory : []byte
+11
View File
@@ -456,6 +456,17 @@ is_power_of_two :: proc "contextless" (x: uintptr) -> bool {
return (x & (x-1)) == 0
}
/*
Check if a pointer is aligned.
This procedure checks whether a pointer `x` is aligned to a boundary specified
by `align`, and returns `true` if the pointer is aligned, and false otherwise.
*/
is_aligned :: proc "contextless" (x: rawptr, align: int) -> bool {
p := uintptr(x)
return (p & (1<<uintptr(align) - 1)) == 0
}
/*
Align uintptr forward.