mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-27 09:50:03 +00:00
[mem]: Fix handling of default resize to check alignment
This commit is contained in:
+1
-1
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user