Skip to content

Commit

Permalink
Fixed "memory access out of bounds"
Browse files Browse the repository at this point in the history
  • Loading branch information
lupyuen committed May 28, 2023
1 parent 949a730 commit 43fa982
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Binary file modified lvglwasm.wasm
Binary file not shown.
9 changes: 5 additions & 4 deletions lvglwasm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -206,17 +206,18 @@ export fn malloc(size: usize) ?*anyopaque {

/// Zig replacement for realloc
export fn realloc(old_mem: [*c]u8, size: usize) ?*anyopaque {
if (old_mem != null) {
// TODO: How to free without the slice length?
// memory_allocator.allocator().free(old_mem[0..???]);
}
// TODO: Call realloc instead
// const mem = memory_allocator.allocator().realloc(old_mem[0..???], size) catch {
// @panic("*** realloc error: out of memory");
// };
const mem = memory_allocator.allocator().alloc(u8, size) catch {
@panic("*** realloc error: out of memory");
};
_ = memcpy(mem.ptr, old_mem, size);
if (old_mem != null) {
// TODO: How to free without the slice length?
// memory_allocator.allocator().free(old_mem[0..???]);
}
return mem.ptr;
}

Expand Down

0 comments on commit 43fa982

Please sign in to comment.