[prev in list] [next in list] [prev in thread] [next in thread] 

List:       uclibc
Subject:    [PATCH] libc/stdlib/malloc/realloc.c: Fix failure when doing realloc(mem, -1).
From:       james.coleman () ubicom ! com (James Coleman)
Date:       2009-07-30 19:58:31
Message-ID: 1248983911-6064-1-git-send-email-jcoleman () ubicom ! com
[Download RAW message or body]

Now check that new_size is > ((unsigned long)-(MALLOC_HEADER_SIZE*2)),
which is the same test that is found in malloc.

This fixes a test failure in test/malloc/tst-mcheck.

Signed-off-by: James Coleman <jcoleman at ubicom.com>
---

Please ignore the last patch that I sent, this one is correct and
actually compiles.

Many apologies.

James.
 	
 libc/stdlib/malloc/realloc.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/libc/stdlib/malloc/realloc.c b/libc/stdlib/malloc/realloc.c
index a827199..aad2b3f 100644
--- a/libc/stdlib/malloc/realloc.c
+++ b/libc/stdlib/malloc/realloc.c
@@ -27,8 +27,10 @@ realloc (void *mem, size_t new_size)
   size_t size;
   char *base_mem;
 
-  /* Check for special cases.  */
-  if (! new_size)
+  /* Check for special cases, such as realloc(mem, 0) or if they are
+     doing something dumb like realloc(mem, -1) */
+  if (unlikely(! new_size) ||
+      unlikely(((unsigned long)new_size > (unsigned long)(MALLOC_HEADER_SIZE*-2))))
     {
       free (mem);
       return malloc (new_size);
-- 
1.6.1.1


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic