diff options
| author | kkHAIKE <kkhaike@gmail.com> | 2022-09-15 18:43:52 +0800 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-10-29 17:53:56 -0400 |
| commit | 949cca9f2a6a84ce1327bde3e982894bc8d91536 (patch) | |
| tree | bead815377f3333343cf67bc31cfc89792f23a02 /lib/std | |
| parent | 28dc208f65c0a3feca4d6018fb316d7c219d29a7 (diff) | |
| download | zig-949cca9f2a6a84ce1327bde3e982894bc8d91536.tar.gz zig-949cca9f2a6a84ce1327bde3e982894bc8d91536.zip | |
Allocator: fix len_align calc in large type size case
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/mem/Allocator.zig | 6 |
1 files 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)) { |
