summaryrefslogtreecommitdiff
path: root/libc/stdlib/malloc/malloc.c
diff options
context:
space:
mode:
authorMiles Bader <miles@lsi.nec.co.jp>2003-10-16 10:12:45 +0000
committerMiles Bader <miles@lsi.nec.co.jp>2003-10-16 10:12:45 +0000
commit0a8bcf917a6e98593629e4641e2e9e12c7e5a8fa (patch)
treecf0ee449b70139f234803803d0ea2f81f1a1ebeb /libc/stdlib/malloc/malloc.c
parent2d421e4f94a0d6847efe7b12b1c2fd85762a44f6 (diff)
Don't set errno if for zero SIZE returns.
Code formatting cleanup.
Diffstat (limited to 'libc/stdlib/malloc/malloc.c')
-rw-r--r--libc/stdlib/malloc/malloc.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/libc/stdlib/malloc/malloc.c b/libc/stdlib/malloc/malloc.c
index 98ac41cd7..5ba552d25 100644
--- a/libc/stdlib/malloc/malloc.c
+++ b/libc/stdlib/malloc/malloc.c
@@ -186,23 +186,26 @@ malloc (size_t size)
__heap_check (&__malloc_heap, "malloc");
#endif
-#if defined(__MALLOC_GLIBC_COMPAT__)
- if (unlikely(size == 0))
- size++;
+#ifdef __MALLOC_GLIBC_COMPAT__
+ if (unlikely (size == 0))
+ size++;
#else
/* Some programs will call malloc (0). Lets be strict and return NULL */
- if (unlikely(size == 0))
- goto oom;
+ if (unlikely (size == 0))
+ return 0;
#endif
+
/* Check if they are doing something dumb like malloc(-1) */
if (unlikely(((unsigned long)size > (unsigned long)(MALLOC_HEADER_SIZE*-2))))
- goto oom;
+ goto oom;
mem = malloc_from_heap (size, &__malloc_heap);
- if (unlikely(!mem)) {
-oom:
- __set_errno(ENOMEM);
- return NULL;
- }
+ if (unlikely (!mem))
+ {
+ oom:
+ __set_errno (ENOMEM);
+ return 0;
+ }
+
return mem;
}