Allocate minimum 1 byte in malloc_nofail when size is 0 to prevent process abort

This commit is contained in:
Andrea Mazzoleni 2026-07-02 16:30:47 +02:00
parent 29a50a7cc4
commit 06351413b7

View file

@ -2142,7 +2142,7 @@ void malloc_fail(size_t size)
void* malloc_nofail(size_t size)
{
void* ptr = malloc(size);
void* ptr = malloc(size ? size : 1);
if (!ptr) {
/* LCOV_EXCL_START */
@ -2175,7 +2175,7 @@ void* calloc_nofail(size_t count, size_t size)
size *= count;
/* see the note in malloc_nofail() of why we don't use calloc() */
ptr = malloc(size);
ptr = malloc(size ? size : 1);
if (!ptr) {
/* LCOV_EXCL_START */