Moved overflow check into end_point function.

This commit is contained in:
David Wood 2018-01-14 00:23:35 +00:00
parent f6fee2a479
commit c6e6428d1a
No known key found for this signature in database
GPG key ID: 01760B4F9F53F154
2 changed files with 4 additions and 7 deletions

View file

@ -219,7 +219,9 @@ impl Span {
/// Returns a new span representing just the end-point of this span
pub fn end_point(self) -> Span {
let span = self.data();
let lo = cmp::max(span.hi.0 - 1, span.lo.0);
// We can avoid an ICE by checking if subtraction would cause an overflow.
let hi = if span.hi.0 == u32::min_value() { span.hi.0 } else { span.hi.0 - 1 };
let lo = cmp::max(hi, span.lo.0);
span.with_lo(BytePos(lo))
}