From aef002e3ce1339ba6e0040b6a79d28e543497427 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Wed, 8 Jul 2009 13:36:26 -0700 Subject: [PATCH] libc - use a valid pointer for malloc(0). This fixes an issue with qsort()ing 0 elements. Reported-by: smtms --- lib/libc/stdlib/nmalloc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/libc/stdlib/nmalloc.c b/lib/libc/stdlib/nmalloc.c index faa1e5cc60..e6bb2b011a 100644 --- a/lib/libc/stdlib/nmalloc.c +++ b/lib/libc/stdlib/nmalloc.c @@ -183,7 +183,7 @@ typedef struct slglobaldata { */ #define WEIRD_ADDR 0xdeadc0de #define MAX_COPY sizeof(weirdary) -#define ZERO_LENGTH_PTR ((void *)-8) +#define ZERO_LENGTH_PTR ((void *)&malloc_dummy_pointer) #define BIGHSHIFT 10 /* bigalloc hash table */ #define BIGHSIZE (1 << BIGHSHIFT) @@ -219,6 +219,7 @@ static struct slglobaldata SLGlobalData[SLGD_MAX]; static bigalloc_t bigalloc_array[BIGHSIZE]; static spinlock_t bigspin_array[BIGXSIZE]; static int malloc_panic; +static int malloc_dummy_pointer; static const int32_t weirdary[16] = { WEIRD_ADDR, WEIRD_ADDR, WEIRD_ADDR, WEIRD_ADDR, -- 2.41.0