Fix panic when size 0 passed to malloc

This commit is contained in:
Anuraag Agrawal
2022-11-21 13:25:24 +09:00
committed by Ron Evans
parent c759e6fc2d
commit b731919f97
2 changed files with 37 additions and 0 deletions
+29
View File
@@ -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)
}
}