Fix overlapping memcpy

memcpy is not safe with overlapping areas and acts randomly on recent 64b linux.