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

Fixes #671
Merge pull request #675 from rectalogic/memcpy-fix

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