Skip to content

Commit 43fa982

Browse files
committed
Fixed "memory access out of bounds"
1 parent 949a730 commit 43fa982

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

lvglwasm.wasm

464 Bytes
Binary file not shown.

lvglwasm.zig

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,17 +206,18 @@ export fn malloc(size: usize) ?*anyopaque {
206206

207207
/// Zig replacement for realloc
208208
export fn realloc(old_mem: [*c]u8, size: usize) ?*anyopaque {
209-
if (old_mem != null) {
210-
// TODO: How to free without the slice length?
211-
// memory_allocator.allocator().free(old_mem[0..???]);
212-
}
213209
// TODO: Call realloc instead
214210
// const mem = memory_allocator.allocator().realloc(old_mem[0..???], size) catch {
215211
// @panic("*** realloc error: out of memory");
216212
// };
217213
const mem = memory_allocator.allocator().alloc(u8, size) catch {
218214
@panic("*** realloc error: out of memory");
219215
};
216+
_ = memcpy(mem.ptr, old_mem, size);
217+
if (old_mem != null) {
218+
// TODO: How to free without the slice length?
219+
// memory_allocator.allocator().free(old_mem[0..???]);
220+
}
220221
return mem.ptr;
221222
}
222223

0 commit comments

Comments
 (0)