[Zlib-devel] Causality question

Mark Adler madler at madler.net
Sun Apr 28 18:43:19 EDT 2013


On Mar 15, 2013, at 12:42 PM, Arjan van de Ven <arjanvandeven at gmail.com> wrote:
> that does mean that using byte copies is mandatory (eg memmove() not
> memcpy()) instead of faster copy variants

Actually you can't use either.  Officially the behavior of memcpy() is undefined when the regions overlap.  The behavior is defined for memmove(), but it is defined to do the copy in a "non-destructive" manner, which means that it will do the copy in back to front if needed to avoid writing over what is being copied.  inflate needs the copy to copy over what is being copied in order to duplicate the initial part of the string.  Usually memcpy() does that, but it cannot be relied upon for that.

Mark





More information about the Zlib-devel mailing list