Use memmove instead of memcpy since src/dest may be overlapping.

Fixes #671