fix memcpy comparison order of operations bugs