Kaydet (Commit) 8a3bb935 authored tarafından Michael Stahl's avatar Michael Stahl

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 4b69497e)

Change-Id: I0981707a61aee1733e727b1c00346d8ec524362e
üst 54dfb9ff
...@@ -227,7 +227,7 @@ namespace treeview { ...@@ -227,7 +227,7 @@ namespace treeview {
static void subst( OUString& instpath ); 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); void Check(TVDom* tvDom);
......
...@@ -61,11 +61,10 @@ namespace treeview { ...@@ -61,11 +61,10 @@ namespace treeview {
return children.back().get(); return children.back().get();
} }
TVDom* newChild(TVDom* p) void newChild(std::unique_ptr<TVDom> p)
{ {
children.emplace_back( p ); children.emplace_back(std::move(p));
p->parent = this; children.back()->parent = this;
return children.back().get();
} }
TVDom* getParent() const TVDom* getParent() const
...@@ -448,8 +447,13 @@ void TVChildTarget::Check(TVDom* tvDom) ...@@ -448,8 +447,13 @@ void TVChildTarget::Check(TVDom* tvDom)
TVDom* p = tvDom->children.back().get(); TVDom* p = tvDom->children.back().get();
for(auto & k : p->children) 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(); tvDom->children.pop_back();
h = true; h = true;
...@@ -458,9 +462,10 @@ void TVChildTarget::Check(TVDom* tvDom) ...@@ -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; bool h = false;
sal_Int32 max = 0; sal_Int32 max = 0;
...@@ -481,8 +486,8 @@ bool TVChildTarget::SearchAndInsert(TVDom* p, TVDom* tvDom) ...@@ -481,8 +486,8 @@ bool TVChildTarget::SearchAndInsert(TVDom* p, TVDom* tvDom)
if (p_int==c_int) if (p_int==c_int)
{ {
(*(tvDom->children.insert(i+1, std::unique_ptr<TVDom>(p))))->parent = tvDom; (*(tvDom->children.insert(i+1, std::move(p))))->parent = tvDom;
return true; return nullptr;
} }
else if(c_int>max && c_int < p_int) else if(c_int>max && c_int < p_int)
{ {
...@@ -491,17 +496,20 @@ bool TVChildTarget::SearchAndInsert(TVDom* p, TVDom* tvDom) ...@@ -491,17 +496,20 @@ bool TVChildTarget::SearchAndInsert(TVDom* p, TVDom* tvDom)
} }
} }
if (h) 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 else
{ {
i = tvDom->children.begin(); 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; ++i;
} }
return p;
} }
return h;
} }
Any SAL_CALL Any SAL_CALL
......
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