From 15c04fd16e2f6a8725311eeff9f5093524c6cf4f Mon Sep 17 00:00:00 2001 From: Jeff Johnston Date: Fri, 3 Jun 2005 18:57:30 +0000 Subject: [PATCH] 2005-06-03 Jeff Johnston * libc/stdlib/mallocr.c (MALLOC_COPY): Switch to use memmove instead of memcpy. --- newlib/ChangeLog | 5 +++++ newlib/libc/stdlib/mallocr.c | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/newlib/ChangeLog b/newlib/ChangeLog index 6e01cd3d0..52df833e0 100644 --- a/newlib/ChangeLog +++ b/newlib/ChangeLog @@ -1,3 +1,8 @@ +2005-06-03 Jeff Johnston + + * libc/stdlib/mallocr.c (MALLOC_COPY): Switch to use memmove + instead of memcpy. + 2005-05-12 Jeff Johnston * configure.host (mn10300-*): Add long long I/O support by default. diff --git a/newlib/libc/stdlib/mallocr.c b/newlib/libc/stdlib/mallocr.c index 71886c14f..02f6a5d15 100644 --- a/newlib/libc/stdlib/mallocr.c +++ b/newlib/libc/stdlib/mallocr.c @@ -487,6 +487,10 @@ extern void __malloc_unlock(); #define HAVE_MEMCPY +/* Although the original macro is called USE_MEMCPY, newlib actually + uses memmove to handle cases whereby a platform's memcpy implementation + copies backwards and thus destructive overlap may occur in realloc + whereby we are reclaiming free memory prior to the old allocation. */ #ifndef USE_MEMCPY #ifdef HAVE_MEMCPY #define USE_MEMCPY 1 @@ -500,9 +504,11 @@ extern void __malloc_unlock(); #if __STD_C void* memset(void*, int, size_t); void* memcpy(void*, const void*, size_t); +void* memmove(void*, const void*, size_t); #else Void_t* memset(); Void_t* memcpy(); +Void_t* memmove(); #endif #endif @@ -544,7 +550,7 @@ do { \ *mcdst++ = *mcsrc++; \ *mcdst++ = *mcsrc++; \ *mcdst = *mcsrc ; \ - } else memcpy(dest, src, mcsz); \ + } else memmove(dest, src, mcsz); \ } while(0) #else /* !USE_MEMCPY */