Protect memcpy calls against undefined behaviour