authorgravatar for kkhaike@gmail.comkkHAIKE <kkhaike@gmail.com> 2022-09-15 18:43:52+08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-10-29 17:53:56-04:00
log949cca9f2a6a84ce1327bde3e982894bc8d91536
treebead815377f3333343cf67bc31cfc89792f23a02
parent28dc208f65c0a3feca4d6018fb316d7c219d29a7

Allocator: fix len_align calc in large type size case


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

lib/std/mem/Allocator.zig+3-3
......@@ -294,10 +294,10 @@ pub fn allocAdvancedWithRetAddr(
294294 // TODO The `if (alignment == null)` blocks are workarounds for zig not being able to
295295 // access certain type information about T without creating a circular dependency in async
296296 // functions that heap-allocate their own frame with @Frame(func).
297 const size_of_T = if (alignment == null) @intCast(u29, @divExact(byte_count, n)) else @sizeOf(T);
297 const size_of_T: usize = if (alignment == null) @divExact(byte_count, n) else @sizeOf(T);
298298 const len_align: u29 = switch (exact) {
299299 .exact => 0,
300 .at_least => size_of_T,
300 .at_least => math.cast(u29, size_of_T) orelse 0,
301301 };
302302 const byte_slice = try self.rawAlloc(byte_count, a, len_align, return_address);
303303 switch (exact) {
......@@ -393,7 +393,7 @@ pub fn reallocAdvancedWithRetAddr(
393393 // Note: can't set shrunk memory to undefined as memory shouldn't be modified on realloc failure
394394 const len_align: u29 = switch (exact) {
395395 .exact => 0,
396 .at_least => @sizeOf(T),
396 .at_least => math.cast(u29, @as(usize, @sizeOf(T))) orelse 0,
397397 };
398398
399399 if (mem.isAligned(@ptrToInt(old_byte_slice.ptr), new_alignment)) {