Browse Source

LibC: Let malloc(0) return nullptr.

Andreas Kling 6 years ago
parent
commit
cfa197f821
1 changed files with 3 additions and 0 deletions
  1. 3 0
      LibC/stdlib.cpp

+ 3 - 0
LibC/stdlib.cpp

@@ -42,6 +42,9 @@ static uint32_t s_malloc_sum_free = POOL_SIZE;
 
 
 void* malloc(size_t size)
 void* malloc(size_t size)
 {
 {
+    if (size == 0)
+        return nullptr;
+
     // We need space for the MallocHeader structure at the head of the block.
     // We need space for the MallocHeader structure at the head of the block.
     size_t real_size = size + sizeof(MallocHeader) + sizeof(MallocFooter);
     size_t real_size = size + sizeof(MallocHeader) + sizeof(MallocFooter);