summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2017-12-08 15:59:53 +0100
committerAndras Timar <andras.timar@collabora.com>2018-04-07 17:46:37 +0200
commit8ec7486174233c5bf99eafce9acf20fe5b7c68c3 (patch)
tree363f3ab26d2322ab72d8614cfa70617b2c15aab0
parentofz#6999 check available data len (diff)
downloadcore-8ec7486174233c5bf99eafce9acf20fe5b7c68c3.tar.gz
core-8ec7486174233c5bf99eafce9acf20fe5b7c68c3.zip
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 (cherry picked from commit f161cdc979587488df83e63002bee7ee15152d42) Reviewed-on: https://gerrit.libreoffice.org/51934 Reviewed-by: Stephan Bergmann <sbergman@redhat.com> Tested-by: Jenkins <ci@libreoffice.org> (cherry picked from commit c4946ba195c9f0c2fb3f18f1028eea725c920e2e) Change-Id: I24133fb6c52bd7500037364120cb11d1b1f099c2 8aeed6876d80b7ebe4ebb5e2cfd12e00420bd207
-rw-r--r--sc/inc/dbdata.hxx9
-rw-r--r--sc/qa/unit/ucalc_sharedformula.cxx4
-rw-r--r--sc/source/filter/xml/xmldrani.cxx5
-rw-r--r--sc/source/ui/docshell/dbdocfun.cxx1
4 files changed, 8 insertions, 11 deletions
diff --git a/sc/inc/dbdata.hxx b/sc/inc/dbdata.hxx
index 328dd2a597e4..df6b88d4dbb9 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 a66a09302667..491573cc86cf 100644
--- a/sc/qa/unit/ucalc_sharedformula.cxx
+++ b/sc/qa/unit/ucalc_sharedformula.cxx
@@ -1637,8 +1637,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.
@@ -1662,8 +1660,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 c525b046cfe2..f7eb3be0d480 100644
--- a/sc/source/filter/xml/xmldrani.cxx
+++ b/sc/source/filter/xml/xmldrani.cxx
@@ -468,10 +468,7 @@ void ScXMLDatabaseRangeContext::EndElement()
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 4cbbd06b2050..c5c5d57ae67d 100644
--- a/sc/source/ui/docshell/dbdocfun.cxx
+++ b/sc/source/ui/docshell/dbdocfun.cxx
@@ -168,7 +168,6 @@ bool ScDBDocFunc::RenameDBRange( const OUString& rOld, const OUString& rNew )
bool bInserted = rDBs.insert(pNewData);
if (!bInserted) // Fehler -> alten Zustand wiederherstellen
{
- delete pNewData;
rDoc.SetDBCollection(pUndoColl); // gehoert dann dem Dokument
}