### Eclipse Workspace Patch 1.0 #P infra Index: current/ChangeLog =================================================================== RCS file: /cvs/ecos/ecos/packages/infra/current/ChangeLog,v retrieving revision 1.59 diff -u -r1.59 ChangeLog --- current/ChangeLog 28 Jun 2007 15:43:07 -0000 1.59 +++ current/ChangeLog 27 Dec 2007 13:54:36 -0000 @@ -1,3 +1,9 @@ +2007-12-28 Oyvind Harboe + + * src/memcpy.cxx: added assert when memory areas for memcpy() + overlaps => result is undefined. It is important to catch *all* + cases of this if adding an optimisation for unaligned copy. + 2007-06-28 Gary Thomas * src/tcdiag.cxx: Index: current/src/memcpy.c =================================================================== RCS file: /cvs/ecos/ecos/packages/infra/current/src/memcpy.c,v retrieving revision 1.6 diff -u -r1.6 memcpy.c --- current/src/memcpy.c 23 May 2002 23:05:52 -0000 1.6 +++ current/src/memcpy.c 27 Dec 2007 13:54:36 -0000 @@ -92,9 +92,12 @@ void * _memcpy( void *s1, const void *s2, size_t n ) { -#if defined(CYGIMP_INFRA_PREFER_SMALL_TO_FAST_MEMCPY) || defined(__OPTIMIZE_SIZE__) char *dst = (char *) s1; const char *src = (const char *) s2; + CYG_ASSERT((dst>=(src+n))||((dst+n)<=src), + "memcpy() has undefined result for overlapping copies"); + +#if defined(CYGIMP_INFRA_PREFER_SMALL_TO_FAST_MEMCPY) || defined(__OPTIMIZE_SIZE__) #ifdef CYG_TRACING_FIXED CYG_REPORT_FUNCNAMETYPE( "_memcpy", "returning %08x" ); @@ -119,8 +122,6 @@ #endif return s1; #else - char *dst; - const char *src; CYG_WORD *aligned_dst; const CYG_WORD *aligned_src; @@ -128,8 +129,6 @@ CYG_REPORT_FUNCNAMETYPE( "_memcpy", "returning %08x" ); #endif - dst = (char *)s1; - src = (const char *)s2; #ifdef CYG_TRACING_FIXED CYG_REPORT_FUNCARG3( "dst=%08x, src=%08x, n=%d", dst, src, n );