diff options
-rw-r--r-- | libc/stdlib/malloc-simple/alloc.c | 3 | ||||
-rw-r--r-- | libc/stdlib/malloc-standard/malloc.c | 5 | ||||
-rw-r--r-- | libc/stdlib/malloc/malloc.c | 2 |
3 files changed, 7 insertions, 3 deletions
diff --git a/libc/stdlib/malloc-simple/alloc.c b/libc/stdlib/malloc-simple/alloc.c index 0b842076d..321f31932 100644 --- a/libc/stdlib/malloc-simple/alloc.c +++ b/libc/stdlib/malloc-simple/alloc.c @@ -32,7 +32,8 @@ void *malloc(size_t size) size++; #else /* Some programs will call malloc (0). Lets be strict and return NULL */ - return 0; + __set_errno(ENOMEM); + return NULL; #endif } diff --git a/libc/stdlib/malloc-standard/malloc.c b/libc/stdlib/malloc-standard/malloc.c index 85b5081e3..3253ebda6 100644 --- a/libc/stdlib/malloc-standard/malloc.c +++ b/libc/stdlib/malloc-standard/malloc.c @@ -826,7 +826,10 @@ void* malloc(size_t bytes) void * retval; #if !defined(__MALLOC_GLIBC_COMPAT__) - if (!bytes) return NULL; + if (!bytes) { + __set_errno(ENOMEM); + return NULL; + } #endif __MALLOC_LOCK; diff --git a/libc/stdlib/malloc/malloc.c b/libc/stdlib/malloc/malloc.c index 2ec8b07da..373b5dcd7 100644 --- a/libc/stdlib/malloc/malloc.c +++ b/libc/stdlib/malloc/malloc.c @@ -200,7 +200,7 @@ malloc (size_t size) #else /* Some programs will call malloc (0). Lets be strict and return NULL */ if (unlikely (size == 0)) - return 0; + goto oom; #endif /* Check if they are doing something dumb like malloc(-1) */ |