commit d02242661e667e67b07faf69490bb0db3dfd4bf0 (tree)
parent ef761c2cbc5c9a06da5c09de389a1d778731d170
Author: Andrew Kelley <andrew@ziglang.org>
Date: Sun, 30 Oct 2022 19:28:26 -0700
std.heap: make wasm32 PageAllocator handle large allocation
When a number of bytes to be allocated is so great that alignForward()
is not possible, return `error.OutOfMemory`.
Companion commit to 3f3003097cbf5a6ad9e0dfc29b2cafbe2e35dded.
Diffstat:
1 file changed, 3 insertions(+), 0 deletions(-)
diff --git a/lib/std/heap.zig b/lib/std/heap.zig
@@ -523,6 +523,9 @@ const WasmPageAllocator = struct {
fn alloc(_: *anyopaque, len: usize, alignment: u29, len_align: u29, ra: usize) error{OutOfMemory}![]u8 {
_ = ra;
+ if (len > maxInt(usize) - (mem.page_size - 1)) {
+ return error.OutOfMemory;
+ }
const page_count = nPages(len);
const page_idx = try allocPages(page_count, alignment);
return @intToPtr([*]u8, page_idx * mem.page_size)[0..alignPageAllocLen(page_count * mem.page_size, len, len_align)];