diff options
author | Gunnar Beutner <gbeutner@serenityos.org> | 2021-05-06 20:35:00 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-06 21:25:37 +0200 |
commit | 017da44ac2afb084d95f28645d956dbcc79ca214 (patch) | |
tree | 4839d4978d4d9b7c2f1eec8da63d4c12b4d87d40 /Userland | |
parent | 0615a4d42aad9a1d90139522790c76a0a94b22a8 (diff) | |
download | serenity-017da44ac2afb084d95f28645d956dbcc79ca214.zip |
LibC: Make malloc(0) return a non-null pointer
Legally we could just return a null pointer, however returning a
pointer other than the null pointer is more compatible with
improperly written software that assumes that a null pointer means
allocation failure.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibC/malloc.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/Userland/Libraries/LibC/malloc.cpp b/Userland/Libraries/LibC/malloc.cpp index 416a4b659b..bf459c7125 100644 --- a/Userland/Libraries/LibC/malloc.cpp +++ b/Userland/Libraries/LibC/malloc.cpp @@ -162,8 +162,11 @@ static void* malloc_impl(size_t size, CallerWillInitializeMemory caller_will_ini if (s_log_malloc) dbgln("LibC: malloc({})", size); - if (!size) - return nullptr; + if (!size) { + // Legally we could just return a null pointer here, but this is more + // compatible with existing software. + size = 1; + } g_malloc_stats.number_of_malloc_calls++; |