[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gzip use of memcpy

From: Alain Magloire
Subject: gzip use of memcpy
Date: Wed, 6 Jan 2010 13:32:40 -0500


The behavior of memcpy is well defined:

"Copying overlapping buffers isn't guaranteed to work; use memmove() to
copy buffers that overlap"

In our case for the SH architecture we have a version of memcpy that
takes advantage at some specific instruction and above a certain size
the copy will be done in reverse (side effect of the optimization).

For overlapping copies, the code should be using memmove() as describe


Please note that I am not subscribed to the list.


# svn diff
Index: inflate.c
--- inflate.c   (revision 248771)
+++ inflate.c   (working copy)
@@ -595,7 +595,7 @@
 #if !defined(NOMEMCPY) && !defined(DEBUG)
         if (w - d >= e)         /* (this test assumes unsigned
comparison) */
-          memcpy(slide + w, slide + d, e);
+          memmove(slide + w, slide + d, e);
           w += e;
           d += e;
Index: deflate.c
--- deflate.c   (revision 248771)
+++ deflate.c   (working copy)
@@ -547,7 +547,7 @@
         Assert(window_size == (ulg)2*WSIZE, "no sliding with BIG_MEM");

-        memcpy((char*)window, (char*)window+WSIZE, (unsigned)WSIZE);
+        memmove((char*)window, (char*)window+WSIZE, (unsigned)WSIZE);
         match_start -= WSIZE;
         strstart    -= WSIZE; /* we now have strstart >= MAX_DIST: */

reply via email to

[Prev in Thread] Current Thread [Next in Thread]