diff options
author | wqfish <wqfish@calibra.com> | 2020-01-13 03:33:33 -0800 |
---|---|---|
committer | Oleksandr Anyshchenko <oleksandr.anyshchenko@xdev.re> | 2020-01-13 13:33:33 +0200 |
commit | 04e75d6ae5a0b41142652994cbc8404b714b5fa1 (patch) | |
tree | a38bbe4ce0b3a086fc721ca03ab407254bafe98a /src | |
parent | a01815d574436a075de8b120d58bae02b32a5d68 (diff) |
Fix potential segfault when calling next on DBIterator that is at the end of the range (#374)
Diffstat (limited to 'src')
-rw-r--r-- | src/db.rs | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -595,6 +595,10 @@ impl<'a> Iterator for DBIterator<'a> { type Item = KVBytes; fn next(&mut self) -> Option<KVBytes> { + if !self.raw.valid() { + return None; + } + // Initial call to next() after seeking should not move the iterator // or the first item will not be returned if !self.just_seeked { @@ -2170,6 +2174,21 @@ fn iterator_test() { } #[test] +fn iterator_test_past_end() { + let path = "_rust_rocksdb_iteratortest_past_end"; + { + let db = DB::open_default(path).unwrap(); + db.put(b"k1", b"v1111").unwrap(); + let mut iter = db.iterator(IteratorMode::Start); + assert!(iter.next().is_some()); + assert!(iter.next().is_none()); + assert!(iter.next().is_none()); + } + let opts = Options::default(); + DB::destroy(&opts, path).unwrap(); +} + +#[test] fn iterator_test_tailing() { let path = "_rust_rocksdb_iteratortest_tailing"; { |