瀏覽代碼

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

Miles Bader 23 年之前
父節點
當前提交
3d909b2123
共有 1 個文件被更改,包括 2 次插入2 次删除
  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;