From 949cca9f2a6a84ce1327bde3e982894bc8d91536 Mon Sep 17 00:00:00 2001 From: kkHAIKE Date: Thu, 15 Sep 2022 18:43:52 +0800 Subject: [PATCH] Allocator: fix len_align calc in large type size case --- lib/std/mem/Allocator.zig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/std/mem/Allocator.zig b/lib/std/mem/Allocator.zig index a574f8f37d..28ca194c29 100644 --- a/lib/std/mem/Allocator.zig +++ b/lib/std/mem/Allocator.zig @@ -294,10 +294,10 @@ pub fn allocAdvancedWithRetAddr( // TODO The `if (alignment == null)` blocks are workarounds for zig not being able to // access certain type information about T without creating a circular dependency in async // functions that heap-allocate their own frame with @Frame(func). - const size_of_T = if (alignment == null) @intCast(u29, @divExact(byte_count, n)) else @sizeOf(T); + const size_of_T: usize = if (alignment == null) @divExact(byte_count, n) else @sizeOf(T); const len_align: u29 = switch (exact) { .exact => 0, - .at_least => size_of_T, + .at_least => math.cast(u29, size_of_T) orelse 0, }; const byte_slice = try self.rawAlloc(byte_count, a, len_align, return_address); switch (exact) { @@ -393,7 +393,7 @@ pub fn reallocAdvancedWithRetAddr( // Note: can't set shrunk memory to undefined as memory shouldn't be modified on realloc failure const len_align: u29 = switch (exact) { .exact => 0, - .at_least => @sizeOf(T), + .at_least => math.cast(u29, @as(usize, @sizeOf(T))) orelse 0, }; if (mem.isAligned(@ptrToInt(old_byte_slice.ptr), new_alignment)) {