Protect fix ported from Radford Neals pqR.