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

Eike Rathke erack at redhat.com
Tue Mar 27 11:11:08 UTC 2018


 sc/inc/dbdata.hxx                  |    9 +++++++--
 sc/qa/unit/ucalc_sharedformula.cxx |    4 ----
 sc/source/filter/xml/xmldrani.cxx  |    5 +----
 sc/source/ui/docshell/dbdocfun.cxx |    1 -
 4 files changed, 8 insertions(+), 11 deletions(-)

New commits:
commit 28632f5c575e1ddc0920041f72686758bf521103
Author: Eike Rathke <erack at redhat.com>
Date:   Fri Dec 8 15:59:53 2017 +0100

    ofz#7121 NamedDBs::insert takes ownership of its argument
    
    at one point this was based on std::auto_ptr and didn't
    free its arg on failure
    
    Adapt description to reality
    
    Change-Id: I24133fb6c52bd7500037364120cb11d1b1f099c2
    (cherry picked from commit f161cdc979587488df83e63002bee7ee15152d42)
    
    Change-Id: I8aeed6876d80b7ebe4ebb5e2cfd12e00420bd207
    Reviewed-on: https://gerrit.libreoffice.org/51933
    Reviewed-by: Stephan Bergmann <sbergman at redhat.com>
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/sc/inc/dbdata.hxx b/sc/inc/dbdata.hxx
index e3aac010d433..7752693765a1 100644
--- a/sc/inc/dbdata.hxx
+++ b/sc/inc/dbdata.hxx
@@ -257,8 +257,13 @@ public:
         ScDBData* findByIndex(sal_uInt16 nIndex);
         ScDBData* findByUpperName(const OUString& rName);
         iterator findByUpperName2(const OUString& rName);
-        // Takes ownership of p iff it returns true:
-        SAL_WARN_UNUSED_RESULT bool insert(ScDBData* p);
+
+        /** Takes ownership of p and attempts to insert it into the collection.
+            Deletes p if it could not be inserted, i.e. duplicate name.
+            @return <TRUE/> if inserted, else <FALSE/>.
+         */
+        bool insert(ScDBData* p);
+
         void erase(const iterator& itr);
         bool empty() const;
         size_t size() const;
diff --git a/sc/qa/unit/ucalc_sharedformula.cxx b/sc/qa/unit/ucalc_sharedformula.cxx
index e46cb5f68c44..b0de3278653c 100644
--- a/sc/qa/unit/ucalc_sharedformula.cxx
+++ b/sc/qa/unit/ucalc_sharedformula.cxx
@@ -1558,8 +1558,6 @@ void Test::testSharedFormulaUpdateOnDBChange()
     // Define database range 'MyRange' for A1:A2.
     ScDBData* pData = new ScDBData("MyRange", 0, 0, 0, 0, 1);
     bool bInserted = pDBs->getNamedDBs().insert(pData);
-    if (!bInserted)
-        delete pData;
     CPPUNIT_ASSERT_MESSAGE("Failed to insert a new database range.", bInserted);
 
     // Insert in C2:C4 a group of formula cells that reference MyRange.
@@ -1583,8 +1581,6 @@ void Test::testSharedFormulaUpdateOnDBChange()
     ScDBCollection aNewDBs(m_pDoc);
     ScDBData* pNewData = new ScDBData("MyRange", 0, 0, 0, 0, 3);
     bInserted = aNewDBs.getNamedDBs().insert(pNewData);
-    if (!bInserted)
-        delete pNewData;
     CPPUNIT_ASSERT_MESSAGE("Failed to insert a new database range.", bInserted);
 
     std::vector<ScRange> aDeleted;
diff --git a/sc/source/filter/xml/xmldrani.cxx b/sc/source/filter/xml/xmldrani.cxx
index c6d1dde218e3..1496c91bfa83 100644
--- a/sc/source/filter/xml/xmldrani.cxx
+++ b/sc/source/filter/xml/xmldrani.cxx
@@ -444,10 +444,7 @@ void SAL_CALL ScXMLDatabaseRangeContext::endFastElement( sal_Int32 /*nElement*/
         if (pData.get())
         {
             setAutoFilterFlags(*pDoc, *pData);
-            if (pDoc->GetDBCollection()->getNamedDBs().insert(pData.get()))
-            {
-                pData.release();
-            }
+            pDoc->GetDBCollection()->getNamedDBs().insert(pData.release());
         }
     }
 }
diff --git a/sc/source/ui/docshell/dbdocfun.cxx b/sc/source/ui/docshell/dbdocfun.cxx
index 02090556c614..d518ff17c03a 100644
--- a/sc/source/ui/docshell/dbdocfun.cxx
+++ b/sc/source/ui/docshell/dbdocfun.cxx
@@ -170,7 +170,6 @@ bool ScDBDocFunc::RenameDBRange( const OUString& rOld, const OUString& rNew )
         bool bInserted = rDBs.insert(pNewData);
         if (!bInserted)                             // error -> restore old state
         {
-            delete pNewData;
             rDoc.SetDBCollection(pUndoColl);       // belongs to the document then
         }
 


More information about the Libreoffice-commits mailing list