Skip to content

Commit 27fc108

Browse files
committed
Fix infinite empty rbtree iteration, bump version to 0.10.5
1 parent e04c70c commit 27fc108

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "eastl-rs"
33
authors = ["Andrew Buck"]
44
description = "EASTL binary-compatible Rust implementations"
55
documentation = "https://docs.rs/crate/eastl-rs"
6-
version = "0.10.4"
6+
version = "0.10.5"
77
edition = "2021"
88
license-file = "LICENSE"
99
readme = "README.md"

src/internal/rb_tree/iter.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
use crate::internal::rb_tree::node::Node;
22
use std::marker::PhantomData;
3+
use std::ptr;
34

45
/// An iterator over a Red-Black tree's nodes.
56
pub struct Iter<'a, K, V> {
67
pub(super) node: *mut Node<K, V>,
8+
pub(super) end: *mut Node<K, V>,
79
pub(super) _marker: PhantomData<&'a ()>,
810
}
911

1012
pub struct IterMut<'a, K, V> {
1113
pub(super) node: *mut Node<K, V>,
14+
pub(super) end: *mut Node<K, V>,
1215
pub(super) _marker: PhantomData<&'a mut ()>,
1316
}
1417

1518
impl<'a, K: 'a, V: 'a> Iterator for Iter<'a, K, V> {
1619
type Item = (&'a K, &'a V);
1720

1821
fn next(&mut self) -> Option<Self::Item> {
22+
if ptr::eq(self.node, self.end) {
23+
return None;
24+
}
25+
1926
unsafe { self.node.as_ref() }
2027
.and_then(Node::next)
2128
.map(|node| (node.key(), node.val()))
@@ -26,6 +33,10 @@ impl<'a, K: 'a, V: 'a> Iterator for IterMut<'a, K, V> {
2633
type Item = (&'a K, &'a mut V);
2734

2835
fn next(&mut self) -> Option<Self::Item> {
36+
if ptr::eq(self.node, self.end) {
37+
return None;
38+
}
39+
2940
unsafe { self.node.as_mut() }
3041
.and_then(Node::next_mut)
3142
.map(|node| (&node.pair.0, &mut node.pair.1))

src/internal/rb_tree/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ impl<K: Eq, V, A: Allocator, C: Compare<K>> RBTree<K, V, A, C> {
171171
pub unsafe fn iter(self: Self) -> Iter<K, V> {
172172
Iter {
173173
node: self.begin,
174+
end: self.end,
174175
_marker: PhantomData,
175176
}
176177
}

0 commit comments

Comments
 (0)