Fixed undefined behaviour from overlapping memcpy.