]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
* elf/dl-minimal.c (realloc): Optimize last patch.
authorJakub Jelinek <jakub@redhat.com>
Fri, 12 Jan 2007 15:02:01 +0000 (15:02 +0000)
committerJakub Jelinek <jakub@redhat.com>
Fri, 12 Jan 2007 15:02:01 +0000 (15:02 +0000)
[BZ #3352]
* elf/dl-minimal.c (realloc): Let malloc() return a new pointer,
and use memcpy() if it does.

ChangeLog
elf/dl-minimal.c

index 15b133867489185474eeb5a88eb8182930395ba4..d3647a8613356910a8f2cd1f6076f727feebdc9b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2006-10-13  Ulrich Drepper  <drepper@redhat.com>
+
+       * elf/dl-minimal.c (realloc): Optimize last patch.
+
+2006-10-12  Richard Sandiford  <richard@codesourcery.com>
+
+       [BZ #3352]
+       * elf/dl-minimal.c (realloc): Let malloc() return a new pointer,
+       and use memcpy() if it does.
+
 2006-10-11  Ulrich Drepper  <drepper@redhat.com>
 
        * sysdeps/unix/sysv/linux/i386/sysdep.h (DOARGS_6): Fix offset.
index 868d3bd2ede07f5ca52522195e2db78a8aa727f6..8e78709b5a825d794eddf16f874333d8bcd9a334 100644 (file)
@@ -1,5 +1,6 @@
 /* Minimal replacements for basic facilities used in the dynamic linker.
-   Copyright (C) 1995-1998,2000-2002,2004,2005 Free Software Foundation, Inc.
+   Copyright (C) 1995-1998,2000-2002,2004,2005,2006
+   Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -128,14 +129,13 @@ free (void *ptr)
 void * weak_function
 realloc (void *ptr, size_t n)
 {
-  void *new;
   if (ptr == NULL)
     return malloc (n);
   assert (ptr == alloc_last_block);
+  size_t old_size = alloc_ptr - alloc_last_block;
   alloc_ptr = alloc_last_block;
-  new = malloc (n);
-  assert (new == ptr);
-  return new;
+  void *new = malloc (n);
+  return new != ptr ? memcpy (new, ptr, old_size) : new;
 }
 \f
 /* Avoid signal frobnication in setjmp/longjmp.  Keeps things smaller.  */