Skip to content

Commit

Permalink
linked-list: update current node when removing element
Browse files Browse the repository at this point in the history
otherwise use after free
  • Loading branch information
Emerentius committed Aug 4, 2019
1 parent b9d3e0a commit 86b7e6c
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions exercises/linked-list/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,20 @@ impl<'a, T: 'a> Cursor<'a, T> {
let prev = node.unlink_prev();

match (prev, next) {
(Some(prev), Some(next)) => NodePtr::link(prev, next),
(Some(_), None) => self.list.head = prev,
(None, Some(_)) => self.list.tail = next,
(Some(prev), Some(next)) => {
self.node = Some(next);
NodePtr::link(prev, next);
},
(Some(_), None) => {
self.node = prev;
self.list.head = prev;
},
(None, Some(_)) => {
self.node = next;
self.list.tail = next;
},
_ => {
self.node = None;
self.list.head = None;
self.list.tail = None;
},
Expand Down

0 comments on commit 86b7e6c

Please sign in to comment.