zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 9d7082972e8df9105b48a806e7bfabca90d4dc1b (tree)
parent f6af773578e20dbae3bf2a350c036558fea84803
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Sat, 24 Feb 2024 18:21:08 -0700

std.heap.raw_c_allocator: use malloc_size for resize

std.heap.c_allocator was already doing this, however,
std.heap.raw_c_allocator, which asserts no allocations more than 16
bytes aligned, was not.

The zig compiler uses std.heap.raw_c_allocator, so it is affected by
this.

Diffstat:
Mlib/std/heap.zig | 11++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/lib/std/heap.zig b/lib/std/heap.zig @@ -196,7 +196,16 @@ fn rawCResize( ) bool { _ = log2_old_align; _ = ret_addr; - return new_len <= buf.len; + + if (new_len <= buf.len) + return true; + + if (CAllocator.supports_malloc_size) { + const full_len = CAllocator.malloc_size(buf.ptr); + if (new_len <= full_len) return true; + } + + return false; } fn rawCFree(