aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFeoramund <161657516+Feoramund@users.noreply.github.com>2025-06-19 19:36:14 -0400
committerFeoramund <161657516+Feoramund@users.noreply.github.com>2025-06-19 19:41:39 -0400
commitc2f3d074e34eecce2bb7dc2cf11ef2d5d65c019d (patch)
treecdc1d34d4099f8acaedead39bc66393c95676569
parent57e2d8f1ddf356a0bfabec7630c1e7ff0199f800 (diff)
mem: Forbid construction of `Buddy_Allocator` with insufficient space
This takes into account eventual alignment.
-rw-r--r--core/mem/allocators.odin1
1 files changed, 1 insertions, 0 deletions
diff --git a/core/mem/allocators.odin b/core/mem/allocators.odin
index e3b96a8f7..a5a7d9951 100644
--- a/core/mem/allocators.odin
+++ b/core/mem/allocators.odin
@@ -2239,6 +2239,7 @@ buddy_allocator_init :: proc(b: ^Buddy_Allocator, data: []byte, alignment: uint,
b.head.is_free = true
b.tail = buddy_block_next(b.head)
b.alignment = alignment
+ assert(uint(len(data)) >= 2 * buddy_block_size_required(b, 1), "The size of the backing buffer must be large enough to hold at least two 1-byte allocations given the alignment requirements, otherwise it cannot split.", loc)
// sanitizer.address_poison(data)
}