add nil check to heap_alloc calls (issue 2530)

This commit is contained in:
jason
2023-05-11 14:04:09 -04:00
parent 82561cfbac
commit f9c600a760
4 changed files with 4 additions and 4 deletions

View File

@@ -194,7 +194,7 @@ heap_allocator_proc :: proc(allocator_data: rawptr, mode: mem.Allocator_Mode,
ptr := uintptr(aligned_mem)
aligned_ptr := (ptr - 1 + uintptr(a)) & -uintptr(a)
diff := int(aligned_ptr - ptr)
if (size + diff) > space {
if (size + diff) > space || allocated_mem == nil {
return nil, .Out_Of_Memory
}

View File

@@ -166,7 +166,7 @@ _heap_allocator_proc :: proc(allocator_data: rawptr, mode: mem.Allocator_Mode,
ptr := uintptr(aligned_mem)
aligned_ptr := (ptr - 1 + uintptr(a)) & -uintptr(a)
diff := int(aligned_ptr - ptr)
if (size + diff) > space {
if (size + diff) > space || allocated_mem == nil {
return nil, .Out_Of_Memory
}

View File

@@ -52,7 +52,7 @@ _heap_allocator_proc :: proc(allocator_data: rawptr, mode: mem.Allocator_Mode,
ptr := uintptr(aligned_mem)
aligned_ptr := (ptr - 1 + uintptr(a)) & -uintptr(a)
diff := int(aligned_ptr - ptr)
if (size + diff) > space {
if (size + diff) > space || allocated_mem == nil {
return nil, .Out_Of_Memory
}

View File

@@ -112,7 +112,7 @@ _windows_default_alloc_or_resize :: proc "contextless" (size, alignment: int, ol
ptr := uintptr(aligned_mem)
aligned_ptr := (ptr - 1 + uintptr(a)) & -uintptr(a)
diff := int(aligned_ptr - ptr)
if (size + diff) > space {
if (size + diff) > space || allocated_mem == nil {
return nil, .Out_Of_Memory
}