summaryrefslogtreecommitdiff
path: root/libc/stdlib/malloc-simple/alloc.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-04-25 16:09:48 +0000
committerEric Andersen <andersen@codepoet.org>2001-04-25 16:09:48 +0000
commit03938380c0e658f55f1df412f2d482f5000f45a6 (patch)
treef4b9ad1dc6199876f9494637d28ecc74de47bea0 /libc/stdlib/malloc-simple/alloc.c
parent3272f0e747a1b9c5305c206d47aab96f7ae5a9c3 (diff)
Be more strict with the malloc implementation. Return NULL
when folks do a malloc(0) using malloc-simple. -Erik
Diffstat (limited to 'libc/stdlib/malloc-simple/alloc.c')
-rw-r--r--libc/stdlib/malloc-simple/alloc.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/libc/stdlib/malloc-simple/alloc.c b/libc/stdlib/malloc-simple/alloc.c
index 02231fbed..630f4c8c8 100644
--- a/libc/stdlib/malloc-simple/alloc.c
+++ b/libc/stdlib/malloc-simple/alloc.c
@@ -25,13 +25,13 @@ void *calloc_dbg(size_t num, size_t size, char *function, char *file,
#ifdef L_malloc_dbg
-void *malloc_dbg(size_t len, char *function, char *file, int line)
+void *malloc_dbg(size_t size, char *function, char *file, int line)
{
void *result;
- fprintf(stderr, "malloc of %d bytes at %s @%s:%d = ", len, function,
+ fprintf(stderr, "malloc of %d bytes at %s @%s:%d = ", size, function,
file, line);
- result = malloc(len);
+ result = malloc(size);
fprintf(stderr, "%p\n", result);
return result;
}
@@ -65,9 +65,14 @@ void *calloc(size_t num, size_t size)
#ifdef L_malloc
-void *malloc(size_t len)
+void *malloc(size_t size)
{
- void *result = mmap((void *) 0, len, PROT_READ | PROT_WRITE,
+#if 1
+ /* Some programs will call malloc (0). Lets be strict and return NULL */
+ if (size == 0)
+ return NULL;
+#endif
+ void *result = mmap((void *) 0, size, PROT_READ | PROT_WRITE,
#ifdef __UCLIBC_HAS_MMU__
MAP_PRIVATE | MAP_ANONYMOUS, 0, 0
#else