Skip to content

Commit

Permalink
Fix integer underflow situation on empty lists.
Browse files Browse the repository at this point in the history
  • Loading branch information
bodil committed Apr 6, 2018
1 parent 286b270 commit 901270a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,11 @@ impl<A> Vector<A> {
///
/// Time: O(log n)
pub fn last(&self) -> Option<Arc<A>> {
self.get(self.len() - 1)
if self.is_empty() {
None
} else {
self.get(self.len() - 1)
}
}

/// Get the vector without the last element.
Expand Down

0 comments on commit 901270a

Please sign in to comment.