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

Fix undefined behavior in intrusive task list

parent 7bc60af3
...@@ -84,13 +84,13 @@ public: ...@@ -84,13 +84,13 @@ public:
// -- operators -------------------------------------------------------------- // -- operators --------------------------------------------------------------
forward_iterator& operator++() { forward_iterator& operator++() {
ptr = promote(ptr->next); ptr = ptr->next;
return *this; return *this;
} }
forward_iterator operator++(int) { forward_iterator operator++(int) {
forward_iterator res = *this; forward_iterator res = *this;
ptr = promote(ptr->next); ptr = ptr->next;
return res; return res;
} }
......
...@@ -173,10 +173,8 @@ public: ...@@ -173,10 +173,8 @@ public:
/// @private /// @private
task_size_type next_task_size() const noexcept { task_size_type next_task_size() const noexcept {
if (head_.next == nullptr) auto ptr = head_.next;
return 0; return ptr != &tail_ ? policy_.task_size(*promote(ptr)) : 0;
auto ptr = promote(head_.next);
return policy_.task_size(*ptr);
} }
/// @private /// @private
...@@ -203,16 +201,6 @@ public: ...@@ -203,16 +201,6 @@ public:
// -- iterator access -------------------------------------------------------- // -- 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. /// Returns an iterator to the dummy before the first element.
iterator begin() noexcept { iterator begin() noexcept {
return head_.next; return head_.next;
...@@ -252,6 +240,7 @@ public: ...@@ -252,6 +240,7 @@ public:
/// Returns a pointer to the last element. /// Returns a pointer to the last element.
pointer back() noexcept { pointer back() noexcept {
CAF_ASSERT(head_.next != &tail_);
return promote(tail_.next); return promote(tail_.next);
} }
...@@ -319,7 +308,7 @@ public: ...@@ -319,7 +308,7 @@ public:
/// @private /// @private
void lifo_append(node_pointer ptr) { void lifo_append(node_pointer ptr) {
if (old_last_ == nullptr) { if (old_last_ == nullptr) {
old_last_ = back(); old_last_ = tail_.next;
push_back(promote(ptr)); push_back(promote(ptr));
} else { } else {
ptr->next = new_head_; ptr->next = new_head_;
......
...@@ -87,7 +87,6 @@ CAF_TEST(default_constructed) { ...@@ -87,7 +87,6 @@ CAF_TEST(default_constructed) {
CAF_REQUIRE_EQUAL(queue.peek(), nullptr); CAF_REQUIRE_EQUAL(queue.peek(), nullptr);
CAF_REQUIRE_EQUAL(queue.next(), nullptr); CAF_REQUIRE_EQUAL(queue.next(), nullptr);
CAF_REQUIRE_EQUAL(queue.begin(), queue.end()); CAF_REQUIRE_EQUAL(queue.begin(), queue.end());
CAF_REQUIRE_EQUAL(queue.before_begin()->next, queue.end().ptr);
} }
CAF_TEST(inc_deficit) { CAF_TEST(inc_deficit) {
......
...@@ -83,7 +83,6 @@ CAF_TEST(default_constructed) { ...@@ -83,7 +83,6 @@ CAF_TEST(default_constructed) {
CAF_REQUIRE_EQUAL(queue.total_task_size(), 0); CAF_REQUIRE_EQUAL(queue.total_task_size(), 0);
CAF_REQUIRE_EQUAL(queue.peek(), nullptr); CAF_REQUIRE_EQUAL(queue.peek(), nullptr);
CAF_REQUIRE_EQUAL(queue.begin(), queue.end()); CAF_REQUIRE_EQUAL(queue.begin(), queue.end());
CAF_REQUIRE_EQUAL(queue.before_begin()->next, queue.end().ptr);
} }
CAF_TEST(push_back) { 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