changeset 2454:1f046a6b2a6c

* 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.
author asl
date Sun, 06 Jan 2008 11:40:45 +0000
parents 9ccbf76434a0
children fcbc1384c4e3
files packages/infra/current/ChangeLog packages/infra/current/src/memcpy.c
diffstat 2 files changed, 11 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/packages/infra/current/ChangeLog
+++ b/packages/infra/current/ChangeLog
@@ -1,3 +1,9 @@
+2007-12-28  Oyvind Harboe <oyvind.harboe@zylin.com>
+	
+	* 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  <gary@mlbassoc.com>
 
 	* src/tcdiag.cxx: 
--- a/packages/infra/current/src/memcpy.c
+++ b/packages/infra/current/src/memcpy.c
@@ -92,9 +92,13 @@ memcpy( void *s1, const void *s2, size_t
 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 +123,6 @@ void *
 #endif
     return s1;
 #else
-    char *dst;
-    const char *src;
     CYG_WORD *aligned_dst;
     const CYG_WORD *aligned_src;
     
@@ -128,8 +130,6 @@ void *
     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 );