From cfa197f821f23e668aa0c034ef6d25def6e32ed9 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 23 Jan 2019 07:32:16 +0100 Subject: [PATCH] LibC: Let malloc(0) return nullptr. --- LibC/stdlib.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/LibC/stdlib.cpp b/LibC/stdlib.cpp index 4be45c7d2f..671f6517cc 100644 --- a/LibC/stdlib.cpp +++ b/LibC/stdlib.cpp @@ -42,6 +42,9 @@ static uint32_t s_malloc_sum_free = POOL_SIZE; void* malloc(size_t size) { + if (size == 0) + return nullptr; + // We need space for the MallocHeader structure at the head of the block. size_t real_size = size + sizeof(MallocHeader) + sizeof(MallocFooter);