From 901270ae70a1a38c8c349f58ae3b0b980fa63d57 Mon Sep 17 00:00:00 2001 From: Bodil Stokke Date: Fri, 6 Apr 2018 15:29:32 +0100 Subject: [PATCH] Fix integer underflow situation on empty lists. --- src/vector.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/vector.rs b/src/vector.rs index 8a916a9..85a3afb 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -206,7 +206,11 @@ impl Vector { /// /// Time: O(log n) pub fn last(&self) -> Option> { - self.get(self.len() - 1) + if self.is_empty() { + None + } else { + self.get(self.len() - 1) + } } /// Get the vector without the last element.