mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
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.
This commit is contained in:
parent
0615a4d42a
commit
017da44ac2
Notes:
sideshowbarker
2024-07-18 18:37:59 +09:00
Author: https://github.com/gunnarbeutner Commit: https://github.com/SerenityOS/serenity/commit/017da44ac2a Pull-request: https://github.com/SerenityOS/serenity/pull/6901
1 changed files with 5 additions and 2 deletions
|
@ -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++;
|
||||
|
||||
|
|
Loading…
Reference in a new issue