diff options
author | Dmitriy Ivanov <dimitry@google.com> | 2015-11-05 17:41:05 -0800 |
---|---|---|
committer | Moritz Horstmann <dev@peterzweg.at> | 2017-07-11 23:17:08 +0200 |
commit | 3aa4e506af80b531d7d9813f05bbf6e4c61e6d27 (patch) | |
tree | ecc2e106edde97add82b9e1a0ee5861de380df76 | |
parent | fe2cc0b7f8032d94aeb5faead7aafbed036aaf58 (diff) | |
download | android_bionic-3aa4e506af80b531d7d9813f05bbf6e4c61e6d27.tar.gz android_bionic-3aa4e506af80b531d7d9813f05bbf6e4c61e6d27.tar.bz2 android_bionic-3aa4e506af80b531d7d9813f05bbf6e4c61e6d27.zip |
Fix linked_list::remove_if()
When remove_if removes last element from the list
following push_back stops working.
AOSP-Change-Id: Ia3e92763b83a2e172eaa10de7aecfb7a4be452d7
(cherry picked from commit 7a9311f7f1f8ac2aa54807039e3af7789dc48c89)
Change-Id: I81b713e9bc32e5586bf303f4fb7f3b18e9e8ca96
-rw-r--r-- | linker/linked_list.h | 6 | ||||
-rw-r--r-- | linker/tests/linked_list_test.cpp | 17 |
2 files changed, 23 insertions, 0 deletions
diff --git a/linker/linked_list.h b/linker/linked_list.h index 8003dbf84..0572e635b 100644 --- a/linker/linked_list.h +++ b/linker/linked_list.h @@ -127,7 +127,13 @@ class LinkedList { } else { p->next = next; } + + if (tail_ == e) { + tail_ = p; + } + Allocator::free(e); + e = next; } else { p = e; diff --git a/linker/tests/linked_list_test.cpp b/linker/tests/linked_list_test.cpp index 09ad68766..12348d9be 100644 --- a/linker/tests/linked_list_test.cpp +++ b/linker/tests/linked_list_test.cpp @@ -133,6 +133,23 @@ TEST(linked_list, remove_if_then_pop) { ASSERT_TRUE(list.pop_front() == nullptr); } +TEST(linked_list, remove_if_last_then_push_back) { + test_list_t list; + + list.push_back("a"); + list.push_back("b"); + list.push_back("c"); + list.push_back("d"); + + list.remove_if([](const char* c) { + return *c == 'c' || *c == 'd'; + }); + + ASSERT_EQ("ab", test_list_to_string(list)); + list.push_back("d"); + ASSERT_EQ("abd", test_list_to_string(list)); +} + TEST(linked_list, copy_to_array) { test_list_t list; const size_t max_size = 128; |