[Libreoffice-commits] core.git: Branch 'libreoffice-6-0' - xmlhelp/source

Michael Stahl mstahl at redhat.com
Fri Dec 15 11:49:50 UTC 2017


 xmlhelp/source/cxxhelp/inc/tvread.hxx |    3 +-
 xmlhelp/source/treeview/tvread.cxx    |   36 ++++++++++++++++++++--------------
 2 files changed, 24 insertions(+), 15 deletions(-)

New commits:
commit dabfbb120dfaca2958f503387a3acac97886e3af
Author: Michael Stahl <mstahl at redhat.com>
Date:   Mon Dec 11 20:00:15 2017 +0100

    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 at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

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


More information about the Libreoffice-commits mailing list