summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2003-08-08 10:30:12 +0000
committerEric Andersen <andersen@codepoet.org>2003-08-08 10:30:12 +0000
commita4ba059034124cbdc0232b805a7fdf07994c8618 (patch)
tree404770803bdcb542f8f5fc82baaf07509e5a06e9
parentea9f6e1e2d60bac4e2c7f1fb9ee98f581a7c6229 (diff)
Add in a MALLOC_GLIBC_COMPAT option to let people decide if they
want glibc style malloc(0) behavior
-rw-r--r--extra/Configs/Config.in19
-rw-r--r--libc/stdlib/malloc-930716/malloc.c5
-rw-r--r--libc/stdlib/malloc/malloc.c5
3 files changed, 28 insertions, 1 deletions
diff --git a/extra/Configs/Config.in b/extra/Configs/Config.in
index 92a3878ff..f77a4e4b5 100644
--- a/extra/Configs/Config.in
+++ b/extra/Configs/Config.in
@@ -195,11 +195,28 @@ config MALLOC_930716
endchoice
+config MALLOC_GLIBC_COMPAT
+ bool "Malloc returns live pointer for malloc(0)"
+ default n
+ help
+ The behavior of malloc(0) is listed as implementation-defined by
+ SuSv3. Glibc returns a valid pointer to something, while uClibc
+ normally return a NULL. I personally feel glibc's behavior is
+ not particularly safe, and allows buggy applications to hide very
+ serious problems.
+
+ When this option is enabled, uClibc will act just like glibc, and
+ return a live pointer when someone calls malloc(0). This pointer
+ provides a malloc'ed area with a size of 1 byte. This feature is
+ mostly useful when dealing with applications using autoconf's broken
+ AC_FUNC_MALLOC macro (which redefines malloc as rpl_malloc if it
+ does not detect glibc style returning-a-valid-pointer-for-malloc(0)
+ behavior). Most people can safely answer N.
+
config UCLIBC_DYNAMIC_ATEXIT
bool "Dynamic atexit() Support"
default y
help
-
When this option is enabled, uClibc will support an infinite number,
of atexit() and on_exit() functions, limited only by your available
memory. This can be important when uClibc is used with C++, since
diff --git a/libc/stdlib/malloc-930716/malloc.c b/libc/stdlib/malloc-930716/malloc.c
index 2467da41c..dce32b90b 100644
--- a/libc/stdlib/malloc-930716/malloc.c
+++ b/libc/stdlib/malloc-930716/malloc.c
@@ -160,9 +160,14 @@ void * __malloc_unlocked (size_t size)
size_t log, block, blocks, i, lastblocks, start;
struct list *next;
+#if defined(__MALLOC_GLIBC_COMPAT__)
+ if (size == 0)
+ size++;
+#else
/* Some programs will call malloc (0). Lets be strict and return NULL */
if (size == 0)
return NULL;
+#endif
if (size < sizeof (struct list))
size = sizeof (struct list);
diff --git a/libc/stdlib/malloc/malloc.c b/libc/stdlib/malloc/malloc.c
index 7bbd2726b..5f88cf48e 100644
--- a/libc/stdlib/malloc/malloc.c
+++ b/libc/stdlib/malloc/malloc.c
@@ -184,8 +184,13 @@ malloc (size_t size)
__heap_check (&__malloc_heap, "malloc");
#endif
+#if defined(__MALLOC_GLIBC_COMPAT__)
if (size == 0)
return 0;
+#else
+ if (size == 0)
+ size++;
+#endif
return malloc_from_heap (size, &__malloc_heap);
}