Skip to content

Commit f06925d

Browse files
SeanTheGleamingVexu
authored andcommitted
Update sbrk_allocator.zig
Reworked pointer logic, reducing usage of `@intFromPtr`
1 parent 09546e7 commit f06925d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/std/heap/sbrk_allocator.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,14 @@ pub fn SbrkAllocator(comptime sbrk: *const fn (n: usize) usize) type {
126126
const class = math.log2(slot_size) - min_class;
127127
const addr = @intFromPtr(buf.ptr);
128128
if (class < size_class_count) {
129-
const node = @as(*usize, @ptrFromInt(addr + (slot_size - @sizeOf(usize))));
129+
const node: *usize = @ptrCast(@alignCast(buf.ptr + slot_size - @sizeOf(usize)));
130130
node.* = frees[class];
131131
frees[class] = addr;
132132
} else {
133133
const bigpages_needed = bigPagesNeeded(actual_len);
134134
const pow2_pages = math.ceilPowerOfTwoAssert(usize, bigpages_needed);
135135
const big_slot_size_bytes = pow2_pages * bigpage_size;
136-
const node = @as(*usize, @ptrFromInt(addr + (big_slot_size_bytes - @sizeOf(usize))));
136+
const node: *usize = @ptrCast(@alignCast(buf.ptr + big_slot_size_bytes - @sizeOf(usize)));
137137
const big_class = math.log2(pow2_pages);
138138
node.* = big_frees[big_class];
139139
big_frees[big_class] = addr;

0 commit comments

Comments
 (0)