Browse Source

In the allocate-and-copy case, don't include the malloc header in our
size calculations.

Miles Bader 23 years ago
parent
commit
3d909b2123
1 changed files with 2 additions and 2 deletions
  1. 2 2
      libc/stdlib/malloc/realloc.c

+ 2 - 2
libc/stdlib/malloc/realloc.c

@@ -52,10 +52,10 @@ realloc (void *mem, size_t new_size)
 	    /* Our attempts to extend MEM in place failed, just
 	       allocate-and-copy.  */
 	    {
-	      void *new_mem = malloc (new_size);
+	      void *new_mem = malloc (new_size - MALLOC_HEADER_SIZE);
 	      if (new_mem)
 		{
-		  memcpy (new_mem, mem, size);
+		  memcpy (new_mem, mem, size - MALLOC_HEADER_SIZE);
 		  free (mem);
 		}
 	      mem = new_mem;