Crash when range is invalid
seppo0010 opened this issue · 3 comments
seppo0010 commented
When the range is invalid (e.g.: min is greater than max) calling skiplist.range crashes.
Ideally it would return an empty Iterator.
Example to reproduce the problem:
diff --git a/src/ordered_skiplist.rs b/src/ordered_skiplist.rs
index 694e9f0..0715242 100644
--- a/src/ordered_skiplist.rs
+++ b/src/ordered_skiplist.rs
@@ -1845,6 +1845,14 @@ mod tests {
}
#[test]
+ fn invalid_range() {
+ let sl: OrderedSkipList<_> = (0..200).collect();
+ let i = 20;
+ let j = 10;
+ assert_eq!(sl.range(Included(&i), Included(&j)).map(|&i| i).collect::<Vec<_>>().len(), 0);
+ }
+
+ #[test]
fn index() {
let size = 1000;
let sl: OrderedSkipList<_> = (0..size).collect();
seppo0010 commented
I just noticed that rust slices also panic when using this sort of range... so I guess the behavior might be ok.
JP-Ellis commented
Thanks for the bug report! I'm not quite sure what you mean when you say that rust slices also panic as they (as far as I know) don't implement a range()
method; however, I just checked the behaviour with BTreeMap
, and does indeed produce an empty iterator.
I shall fix this in the next couple of days.