[git commit] list: fix splice to empty list from other.begin()
Bernhard Reutner-Fischer
rep.dot.nop at gmail.com
Sun Sep 30 18:42:31 UTC 2018
commit: https://git.uclibc.org/uClibc++/commit/?id=c2fd3e7bac717eb783ee046b9a5639d6badcb86c
branch: https://git.uclibc.org/uClibc++/commit/?id=refs/heads/master
Fixes bug 11361
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop at gmail.com>
---
include/list | 4 ++--
tests/listtest.cpp | 26 +++++++++++++++++++++++++-
tests/testoutput/listtest.good | 4 ++++
3 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/include/list b/include/list
index de8edad..1ef00fb 100644
--- a/include/list
+++ b/include/list
@@ -604,8 +604,8 @@ namespace std{
//Insert at begining special case
if(position == begin()){
-
- i.link_struct()->previous->next = i.link_struct()->next;
+ if (i.link_struct()->previous != 0)
+ i.link_struct()->previous->next = i.link_struct()->next;
i.link_struct()->next->previous = i.link_struct()->previous;
i.link_struct()->previous = 0;
diff --git a/tests/listtest.cpp b/tests/listtest.cpp
index c8aa0dd..639654c 100644
--- a/tests/listtest.cpp
+++ b/tests/listtest.cpp
@@ -337,7 +337,31 @@ int main(){
++list_iter_1;
}
std::cout << std::endl;
-
+
+
+ /* bug 11361: splice to empty list from other.begin() segfaulted */
+ temp.clear();
+ a.clear();
+ temp.push_back(1.0);
+ temp.push_back(2.0);
+ a.splice(a.end(), temp, temp.begin());
+ std::cout << "temp.size(): " << temp.size() << std::endl;
+ std::cout << "a.size(): " << a.size() << std::endl;
+ std::cout << "temp:";
+ i = temp.begin();
+ while(i != temp.end()){
+ std::cout << " " << *i;
+ ++i;
+ }
+ std::cout << std::endl;
+ std::cout << "a:";
+ i = a.begin();
+ while(i != a.end()){
+ std::cout << " " << *i;
+ ++i;
+ }
+ std::cout << std::endl;
+
std::cout << "Testing operator=()\n";
temp.clear();
diff --git a/tests/testoutput/listtest.good b/tests/testoutput/listtest.good
index f830dc8..2434490 100644
--- a/tests/testoutput/listtest.good
+++ b/tests/testoutput/listtest.good
@@ -93,6 +93,10 @@ The following two lines should be identical
The following two lines should be identical
1 3 4 2
1 3 4 2
+temp.size(): 1
+a.size(): 1
+temp: 2
+a: 1
Testing operator=()
The following three lines should be identical
12.8 22.4 37.9 48.5 21.2 85.4 24.6 69.7
More information about the uClibc-cvs
mailing list