authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-02-20 22:14:35+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-02-21 23:39:34+01:00
logb5bcbf2a62aa513022fdb12df75699308f87b7bc
tree53598c368c9d3d6824ee4911ae97be5ba4323735
parenta9d18c4a0c2be3d5e7dcedbedc32a9998b1e5515
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

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.

1 files changed, 1 insertions(+), 1 deletions(-)

lib/std/heap/debug_allocator.zig+1-1
...@@ -266,7 +266,7 @@ pub fn DebugAllocator(comptime config: Config) type {...@@ -266,7 +266,7 @@ pub fn DebugAllocator(comptime config: Config) type {
266 canary: usize = config.canary,266 canary: usize = config.canary,
267267
268 fn fromPage(page_addr: usize, slot_count: usize) *BucketHeader {268 fn fromPage(page_addr: usize, slot_count: usize) *BucketHeader {
269 const unaligned = page_addr + page_size - bucketSize(slot_count);269 const unaligned = page_addr +% page_size -% bucketSize(slot_count);
270 return @ptrFromInt(unaligned & ~(@as(usize, @alignOf(BucketHeader)) - 1));270 return @ptrFromInt(unaligned & ~(@as(usize, @alignOf(BucketHeader)) - 1));
271 }271 }
272272