Use memmove() instead of memcpy() on areas that may overlap.