Fix a bug introduced at r259632, triggering infinite loop in some cases.