Commit 628fdab2 authored by Dominik Charousset's avatar Dominik Charousset

Fix undefined behavior in intrusive task list

parent 7bc60af3
......@@ -84,13 +84,13 @@ public:
// -- operators --------------------------------------------------------------
forward_iterator& operator++() {
ptr = promote(ptr->next);
ptr = ptr->next;
return *this;
}
forward_iterator operator++(int) {
forward_iterator res = *this;
ptr = promote(ptr->next);
ptr = ptr->next;
return res;
}
......
......@@ -173,10 +173,8 @@ public:
/// @private
task_size_type next_task_size() const noexcept {
if (head_.next == nullptr)
return 0;
auto ptr = promote(head_.next);
return policy_.task_size(*ptr);
auto ptr = head_.next;
return ptr != &tail_ ? policy_.task_size(*promote(ptr)) : 0;
}
/// @private
......@@ -203,16 +201,6 @@ public:
// -- iterator access --------------------------------------------------------
/// Returns an iterator to the dummy before the first element.
iterator before_begin() noexcept {
return &head_;
}
/// Returns an iterator to the dummy before the first element.
const_iterator before_begin() const noexcept {
return &head_;
}
/// Returns an iterator to the dummy before the first element.
iterator begin() noexcept {
return head_.next;
......@@ -252,6 +240,7 @@ public:
/// Returns a pointer to the last element.
pointer back() noexcept {
CAF_ASSERT(head_.next != &tail_);
return promote(tail_.next);
}
......@@ -319,7 +308,7 @@ public:
/// @private
void lifo_append(node_pointer ptr) {
if (old_last_ == nullptr) {
old_last_ = back();
old_last_ = tail_.next;
push_back(promote(ptr));
} else {
ptr->next = new_head_;
......
......@@ -87,7 +87,6 @@ CAF_TEST(default_constructed) {
CAF_REQUIRE_EQUAL(queue.peek(), nullptr);
CAF_REQUIRE_EQUAL(queue.next(), nullptr);
CAF_REQUIRE_EQUAL(queue.begin(), queue.end());
CAF_REQUIRE_EQUAL(queue.before_begin()->next, queue.end().ptr);
}
CAF_TEST(inc_deficit) {
......
......@@ -83,7 +83,6 @@ CAF_TEST(default_constructed) {
CAF_REQUIRE_EQUAL(queue.total_task_size(), 0);
CAF_REQUIRE_EQUAL(queue.peek(), nullptr);
CAF_REQUIRE_EQUAL(queue.begin(), queue.end());
CAF_REQUIRE_EQUAL(queue.before_begin()->next, queue.end().ptr);
}
CAF_TEST(push_back) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment