commit b5bcbf2a62aa513022fdb12df75699308f87b7bc (tree)
parent a9d18c4a0c2be3d5e7dcedbedc32a9998b1e5515
Author: Alex Rønne Petersen <alex@alexrp.com>
Date: Fri, 20 Feb 2026 22:14:35 +0100
std.heap.DebugAllocator: make BucketHeader.fromPage() use wrapping arithmetic
If we've allocated the very last page in the address space then these operations
will overflow and underflow respectively - which is fine.
Diffstat:
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/std/heap/debug_allocator.zig b/lib/std/heap/debug_allocator.zig
@@ -266,7 +266,7 @@ pub fn DebugAllocator(comptime config: Config) type {
canary: usize = config.canary,
fn fromPage(page_addr: usize, slot_count: usize) *BucketHeader {
- const unaligned = page_addr + page_size - bucketSize(slot_count);
+ const unaligned = page_addr +% page_size -% bucketSize(slot_count);
return @ptrFromInt(unaligned & ~(@as(usize, @alignOf(BucketHeader)) - 1));
}