aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/runtime_wasi
diff options
context:
space:
mode:
authorAnuraag Agrawal <[email protected]>2022-11-21 13:25:24 +0900
committerRon Evans <[email protected]>2022-11-21 21:00:36 +0100
commitb731919f97512e27a492f44942238c21f442c8d0 (patch)
tree56ad08b34b426d89f4e00014f4b26e9dc79baa1c /tests/runtime_wasi
parentc759e6fc2db8caf20098805275f045da97b1fca4 (diff)
downloadtinygo-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.go29
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)
+ }
+}