diff options
author | Anuraag Agrawal <[email protected]> | 2022-11-21 13:25:24 +0900 |
---|---|---|
committer | Ron Evans <[email protected]> | 2022-11-21 21:00:36 +0100 |
commit | b731919f97512e27a492f44942238c21f442c8d0 (patch) | |
tree | 56ad08b34b426d89f4e00014f4b26e9dc79baa1c /tests/runtime_wasi | |
parent | c759e6fc2db8caf20098805275f045da97b1fca4 (diff) | |
download | tinygo-b731919f97512e27a492f44942238c21f442c8d0.tar.gz tinygo-b731919f97512e27a492f44942238c21f442c8d0.zip |
Fix panic when size 0 passed to malloc
Diffstat (limited to 'tests/runtime_wasi')
-rw-r--r-- | tests/runtime_wasi/malloc_test.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/runtime_wasi/malloc_test.go b/tests/runtime_wasi/malloc_test.go index 06b197f13..eb655b424 100644 --- a/tests/runtime_wasi/malloc_test.go +++ b/tests/runtime_wasi/malloc_test.go @@ -125,3 +125,32 @@ func TestMallocFree(t *testing.T) { }) } } + +func TestMallocEmpty(t *testing.T) { + ptr := libc_malloc(0) + if ptr != nil { + t.Errorf("expected nil pointer, got %p", ptr) + } +} + +func TestCallocEmpty(t *testing.T) { + ptr := libc_calloc(0, 1) + if ptr != nil { + t.Errorf("expected nil pointer, got %p", ptr) + } + ptr = libc_calloc(1, 0) + if ptr != nil { + t.Errorf("expected nil pointer, got %p", ptr) + } +} + +func TestReallocEmpty(t *testing.T) { + ptr := libc_malloc(1) + if ptr == nil { + t.Error("expected pointer but was nil") + } + ptr = libc_realloc(ptr, 0) + if ptr != nil { + t.Errorf("expected nil pointer, got %p", ptr) + } +} |