[Libreoffice-commits] core.git: sc/inc sc/source
Caolán McNamara
caolanm at redhat.com
Wed Jun 26 04:02:23 PDT 2013
sc/inc/column.hxx | 11 +++++++++--
sc/inc/document.hxx | 8 +++++++-
sc/inc/table.hxx | 8 +++++++-
sc/source/core/data/column3.cxx | 8 ++++++--
sc/source/core/data/documen2.cxx | 6 +++---
sc/source/core/data/table2.cxx | 6 +++---
sc/source/filter/excel/excform.cxx | 2 +-
sc/source/filter/xml/xmlcelli.cxx | 5 +++--
sc/source/ui/unoobj/funcuno.cxx | 6 +++---
9 files changed, 42 insertions(+), 18 deletions(-)
New commits:
commit 4d676f72bc0f1928be0e6bc2f272291f278dc95a
Author: Caolán McNamara <caolanm at redhat.com>
Date: Tue Jun 25 17:29:24 2013 +0100
coverity#1038508 Use after free (USE_AFTER_FREE)
** CID 1038508: Use after free (USE_AFTER_FREE)
** CID 1038509: Use after free (USE_AFTER_FREE)
** CID 1038510: Use after free (USE_AFTER_FREE)
Change-Id: I3a1422e252af415536d9303e58ff85763c231921
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index e7c58c1..23e3a16 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -255,8 +255,15 @@ public:
void SetEditText( SCROW nRow, const EditTextObject& rEditText, const SfxItemPool* pEditPool );
void SetFormula( SCROW nRow, const ScTokenArray& rArray, formula::FormulaGrammar::Grammar eGram );
void SetFormula( SCROW nRow, const OUString& rFormula, formula::FormulaGrammar::Grammar eGram );
- void SetFormulaCell( SCROW nRow, ScFormulaCell* pCell );
- void SetFormulaCell( sc::ColumnBlockPosition& rBlockPos, SCROW nRow, ScFormulaCell* pCell );
+
+ /**
+ * Takes ownership of pCell
+ *
+ * @return pCell if it was successfully inserted, NULL otherwise. pCell
+ * is deleted automatically on failure to insert.
+ */
+ ScFormulaCell* SetFormulaCell( SCROW nRow, ScFormulaCell* pCell );
+ ScFormulaCell* SetFormulaCell( sc::ColumnBlockPosition& rBlockPos, SCROW nRow, ScFormulaCell* pCell );
void SetRawString( SCROW nRow, const OUString& rStr, bool bBroadcast = true );
void SetRawString( sc::ColumnBlockPosition& rBlockPos, SCROW nRow, const OUString& rStr, bool bBroadcast = true );
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 08c4ab6..ff0b869 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -792,7 +792,13 @@ public:
const ScAddress& rPos, const OUString& rFormula,
formula::FormulaGrammar::Grammar eGram = formula::FormulaGrammar::GRAM_DEFAULT );
- SC_DLLPUBLIC void SetFormulaCell( const ScAddress& rPos, ScFormulaCell* pCell );
+ /**
+ * Takes ownership of pCell
+ *
+ * @return pCell if it was successfully inserted, NULL otherwise. pCell
+ * is deleted automatically on failure to insert.
+ */
+ SC_DLLPUBLIC ScFormulaCell* SetFormulaCell( const ScAddress& rPos, ScFormulaCell* pCell );
SC_DLLPUBLIC void InsertMatrixFormula(SCCOL nCol1, SCROW nRow1,
SCCOL nCol2, SCROW nRow2,
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 65cb180..15f04e5 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -324,7 +324,13 @@ public:
void SetFormula(
SCCOL nCol, SCROW nRow, const OUString& rFormula, formula::FormulaGrammar::Grammar eGram );
- void SetFormulaCell( SCCOL nCol, SCROW nRow, ScFormulaCell* pCell );
+ /**
+ * Takes ownership of pCell
+ *
+ * @return pCell if it was successfully inserted, NULL otherwise. pCell
+ * is deleted automatically on failure to insert.
+ */
+ ScFormulaCell* SetFormulaCell( SCCOL nCol, SCROW nRow, ScFormulaCell* pCell );
void SetValue( SCCOL nCol, SCROW nRow, const double& rVal );
void SetError( SCCOL nCol, SCROW nRow, sal_uInt16 nError);
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index 11c4474..861984e 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -1699,7 +1699,7 @@ void ScColumn::SetFormula( SCROW nRow, const OUString& rFormula, formula::Formul
ActivateNewFormulaCell(pCell);
}
-void ScColumn::SetFormulaCell( SCROW nRow, ScFormulaCell* pCell )
+ScFormulaCell* ScColumn::SetFormulaCell( SCROW nRow, ScFormulaCell* pCell )
{
sc::CellStoreType::iterator it = GetPositionToInsert(nRow);
maCells.set(it, nRow, pCell);
@@ -1707,9 +1707,11 @@ void ScColumn::SetFormulaCell( SCROW nRow, ScFormulaCell* pCell )
CellStorageModified();
ActivateNewFormulaCell(pCell);
+
+ return pCell;
}
-void ScColumn::SetFormulaCell( sc::ColumnBlockPosition& rBlockPos, SCROW nRow, ScFormulaCell* pCell )
+ScFormulaCell* ScColumn::SetFormulaCell( sc::ColumnBlockPosition& rBlockPos, SCROW nRow, ScFormulaCell* pCell )
{
rBlockPos.miCellPos = GetPositionToInsert(rBlockPos.miCellPos, nRow);
rBlockPos.miCellPos = maCells.set(rBlockPos.miCellPos, nRow, pCell);
@@ -1718,6 +1720,8 @@ void ScColumn::SetFormulaCell( sc::ColumnBlockPosition& rBlockPos, SCROW nRow, S
CellStorageModified();
ActivateNewFormulaCell(pCell);
+
+ return pCell;
}
namespace {
diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx
index 7046194..b1b3160 100644
--- a/sc/source/core/data/documen2.cxx
+++ b/sc/source/core/data/documen2.cxx
@@ -1054,15 +1054,15 @@ void ScDocument::SetFormula(
maTabs[rPos.Tab()]->SetFormula(rPos.Col(), rPos.Row(), rFormula, eGram);
}
-void ScDocument::SetFormulaCell( const ScAddress& rPos, ScFormulaCell* pCell )
+ScFormulaCell* ScDocument::SetFormulaCell( const ScAddress& rPos, ScFormulaCell* pCell )
{
if (!TableExists(rPos.Tab()))
{
delete pCell;
- return;
+ return NULL;
}
- maTabs[rPos.Tab()]->SetFormulaCell(rPos.Col(), rPos.Row(), pCell);
+ return maTabs[rPos.Tab()]->SetFormulaCell(rPos.Col(), rPos.Row(), pCell);
}
void ScDocument::SetConsolidateDlgData( const ScConsolidateParam* pData )
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index 3d7b746..cec4679 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -1438,15 +1438,15 @@ void ScTable::SetFormula(
aCol[nCol].SetFormula(nRow, rFormula, eGram);
}
-void ScTable::SetFormulaCell( SCCOL nCol, SCROW nRow, ScFormulaCell* pCell )
+ScFormulaCell* ScTable::SetFormulaCell( SCCOL nCol, SCROW nRow, ScFormulaCell* pCell )
{
if (!ValidColRow(nCol, nRow))
{
delete pCell;
- return;
+ return NULL;
}
- aCol[nCol].SetFormulaCell(nRow, pCell);
+ return aCol[nCol].SetFormulaCell(nRow, pCell);
}
void ScTable::SetValue( SCCOL nCol, SCROW nRow, const double& rVal )
diff --git a/sc/source/filter/excel/excform.cxx b/sc/source/filter/excel/excform.cxx
index 3cb4367..10b95f7 100644
--- a/sc/source/filter/excel/excform.cxx
+++ b/sc/source/filter/excel/excform.cxx
@@ -124,7 +124,7 @@ void ImportExcel::Formula(
{
pCell = new ScFormulaCell( pD, aScPos, pResult );
pD->EnsureTable(aScPos.Tab());
- pD->SetFormulaCell(aScPos, pCell);
+ pCell = pD->SetFormulaCell(aScPos, pCell);
}
else
{
diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index 0fef98f..4ab9d98 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -1344,8 +1344,9 @@ void ScXMLTableRowCellContext::PutFormulaCell( const ScAddress& rCellPos )
pDoc->IncXMLImportedFormulaCount( aText.getLength() );
ScFormulaCell* pNewCell = new ScFormulaCell(pDoc, rCellPos, pCode.get(), eGrammar, MM_NONE);
SetFormulaCell(pNewCell);
- pDoc->SetFormulaCell(rCellPos, pNewCell);
- pNewCell->SetNeedNumberFormat( true );
+ pNewCell = pDoc->SetFormulaCell(rCellPos, pNewCell);
+ if (pNewCell)
+ pNewCell->SetNeedNumberFormat( true );
}
else if ( aText[0] == '\'' && aText.getLength() > 1 )
{
diff --git a/sc/source/ui/unoobj/funcuno.cxx b/sc/source/ui/unoobj/funcuno.cxx
index 7c57ee9..1090ea1 100644
--- a/sc/source/ui/unoobj/funcuno.cxx
+++ b/sc/source/ui/unoobj/funcuno.cxx
@@ -653,13 +653,13 @@ uno::Any SAL_CALL ScFunctionAccess::callFunction( const OUString& aName,
// other API compatibility grammars.
ScFormulaCell* pFormula = new ScFormulaCell( pDoc, aFormulaPos,
&aTokenArr, formula::FormulaGrammar::GRAM_PODF_A1, (sal_uInt8)(mbArray ? MM_FORMULA : MM_NONE) );
- pDoc->SetFormulaCell(aFormulaPos, pFormula);
+ pFormula = pDoc->SetFormulaCell(aFormulaPos, pFormula);
// call GetMatrix before GetErrCode because GetMatrix always recalculates
// if there is no matrix result
- const ScMatrix* pMat = mbArray ? pFormula->GetMatrix() : 0;
- sal_uInt16 nErrCode = pFormula->GetErrCode();
+ const ScMatrix* pMat = (mbArray && pFormula) ? pFormula->GetMatrix() : 0;
+ sal_uInt16 nErrCode = pFormula ? pFormula->GetErrCode() : errIllegalArgument;
if ( nErrCode == 0 )
{
if ( pMat )
More information about the Libreoffice-commits
mailing list