diff options
author | Michael Stahl <mstahl@redhat.com> | 2017-12-11 20:00:15 +0100 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-12-15 12:40:57 +0100 |
commit | dabfbb120dfaca2958f503387a3acac97886e3af (patch) | |
tree | f22bca8fa7f01e0b40f57f1de4fd53481ed3d4ef | |
parent | 0b100b78ccb24a4f8da51433f535030facb77705 (diff) |
tdf#114242 xmlhelp: fix crash in TVChildTarget::Check()
The ... idiomatic C++ code in TVChildTarget::Check() and
SearchAndInsert() handles ownership in non-obvious ways,
so it's not surprising that it took offense at the recent
conversion to std::unique_ptr. Let's at least try to
prevent it from crashing so quickly.
(regression from 4b69497e36b941d4db62ae8d5bad863d032fdc50)
(cherry picked from commit 8a3bb9356219754af7e651a879b5fc8925a18468)
Attempt to blind fix build breaker
(cherry picked from commit 4094f9baf62a426b24f497c86d6a96ccfcb22ad1)
Change-Id: I0981707a61aee1733e727b1c00346d8ec524362e
Reviewed-on: https://gerrit.libreoffice.org/46376
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | xmlhelp/source/cxxhelp/inc/tvread.hxx | 3 | ||||
-rw-r--r-- | xmlhelp/source/treeview/tvread.cxx | 36 |
2 files changed, 24 insertions, 15 deletions
diff --git a/xmlhelp/source/cxxhelp/inc/tvread.hxx b/xmlhelp/source/cxxhelp/inc/tvread.hxx index cd0b22b49e09..087d82b70733 100644 --- a/xmlhelp/source/cxxhelp/inc/tvread.hxx +++ b/xmlhelp/source/cxxhelp/inc/tvread.hxx @@ -36,6 +36,7 @@ #include <com/sun/star/deployment/XPackage.hpp> #include <com/sun/star/ucb/XSimpleFileAccess3.hpp> #include <cppuhelper/implbase.hxx> +#include <memory> namespace treeview { @@ -227,7 +228,7 @@ namespace treeview { static void subst( OUString& instpath ); - bool SearchAndInsert(TVDom* p, TVDom* tvDom); + std::unique_ptr<TVDom> SearchAndInsert(std::unique_ptr<TVDom> p, TVDom* tvDom); void Check(TVDom* tvDom); diff --git a/xmlhelp/source/treeview/tvread.cxx b/xmlhelp/source/treeview/tvread.cxx index 5339a93117d7..3e6ae7afe8af 100644 --- a/xmlhelp/source/treeview/tvread.cxx +++ b/xmlhelp/source/treeview/tvread.cxx @@ -61,11 +61,10 @@ namespace treeview { return children.back().get(); } - TVDom* newChild(TVDom* p) + void newChild(std::unique_ptr<TVDom> p) { - children.emplace_back( p ); - p->parent = this; - return children.back().get(); + children.emplace_back(std::move(p)); + children.back()->parent = this; } TVDom* getParent() const @@ -448,8 +447,13 @@ void TVChildTarget::Check(TVDom* tvDom) TVDom* p = tvDom->children.back().get(); for(auto & k : p->children) - if (!SearchAndInsert(k.get(), tvDom->children[i].get())) - tvDom->children[i]->newChild(k.get()); + { + std::unique_ptr<TVDom> tmp(SearchAndInsert(std::move(k), tvDom->children[i].get())); + if (tmp) + { + tvDom->children[i]->newChild(std::move(tmp)); + } + } tvDom->children.pop_back(); h = true; @@ -458,9 +462,10 @@ void TVChildTarget::Check(TVDom* tvDom) } } -bool TVChildTarget::SearchAndInsert(TVDom* p, TVDom* tvDom) +std::unique_ptr<TVDom> +TVChildTarget::SearchAndInsert(std::unique_ptr<TVDom> p, TVDom* tvDom) { - if (p->isLeaf()) return false; + if (p->isLeaf()) return p; bool h = false; sal_Int32 max = 0; @@ -481,8 +486,8 @@ bool TVChildTarget::SearchAndInsert(TVDom* p, TVDom* tvDom) if (p_int==c_int) { - (*(tvDom->children.insert(i+1, std::unique_ptr<TVDom>(p))))->parent = tvDom; - return true; + (*(tvDom->children.insert(i+1, std::move(p))))->parent = tvDom; + return nullptr; } else if(c_int>max && c_int < p_int) { @@ -491,17 +496,20 @@ bool TVChildTarget::SearchAndInsert(TVDom* p, TVDom* tvDom) } } if (h) - (*(tvDom->children.insert(max_It, std::unique_ptr<TVDom>(p))))->parent = tvDom; + { + (*(tvDom->children.insert(max_It, std::move(p))))->parent = tvDom; + return nullptr; + } else { i = tvDom->children.begin(); - while ((i!=tvDom->children.end()) && (!h)) + while ((i!=tvDom->children.end()) && (p != nullptr)) { - h = SearchAndInsert(p, i->get()); + p = SearchAndInsert(std::move(p), i->get()); ++i; } + return p; } - return h; } Any SAL_CALL |