[Libreoffice-commits] core.git: 2 commits - sc/qa sc/source
Kohei Yoshida
kohei.yoshida at collabora.com
Thu Mar 13 13:10:55 PDT 2014
sc/qa/unit/ucalc.cxx | 31 +++++++++++++++++++++++++++++++
sc/source/core/data/column4.cxx | 35 +++++++++++++++++++++++++----------
2 files changed, 56 insertions(+), 10 deletions(-)
New commits:
commit 36bcab7859b7dfa1f1377bb5865c881742f178dd
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date: Thu Mar 13 16:08:03 2014 -0400
fdo#76132: Don't create a formula group of length 1.
That's asking for trouble.
Change-Id: I6aaa4d1e2aed4f166ee216c3eb02d3b7794c9a8c
diff --git a/sc/source/core/data/column4.cxx b/sc/source/core/data/column4.cxx
index fa18818..2f21623 100644
--- a/sc/source/core/data/column4.cxx
+++ b/sc/source/core/data/column4.cxx
@@ -334,25 +334,40 @@ void ScColumn::CloneFormulaCell( const ScFormulaCell& rSrc, const std::vector<sc
{
SCROW nRow1 = itSpan->mnRow1, nRow2 = itSpan->mnRow2;
size_t nLen = nRow2 - nRow1 + 1;
+ assert(nLen > 0);
aFormulas.clear();
aFormulas.reserve(nLen);
ScAddress aPos(nCol, nRow1, nTab);
- ScFormulaCellGroupRef xGroup(new ScFormulaCellGroup);
- xGroup->setCode(*rSrc.GetCode());
- xGroup->compileCode(*pDocument, aPos, pDocument->GetGrammar());
- for (size_t i = 0; i < nLen; ++i, aPos.IncRow())
+
+ if (nLen == 1)
{
- ScFormulaCell* pCell = new ScFormulaCell(pDocument, aPos, xGroup);
- if (i == 0)
- {
- xGroup->mpTopCell = pCell;
- xGroup->mnLength = nLen;
- }
+ // Single, ungrouped formula cell.
+ ScFormulaCell* pCell =
+ new ScFormulaCell(rSrc, *pDocument, aPos, pDocument->GetGrammar());
pCell->StartListeningTo(aCxt);
pCell->SetDirty();
aFormulas.push_back(pCell);
}
+ else
+ {
+ // Create a group of formula cells.
+ ScFormulaCellGroupRef xGroup(new ScFormulaCellGroup);
+ xGroup->setCode(*rSrc.GetCode());
+ xGroup->compileCode(*pDocument, aPos, pDocument->GetGrammar());
+ for (size_t i = 0; i < nLen; ++i, aPos.IncRow())
+ {
+ ScFormulaCell* pCell = new ScFormulaCell(pDocument, aPos, xGroup);
+ if (i == 0)
+ {
+ xGroup->mpTopCell = pCell;
+ xGroup->mnLength = nLen;
+ }
+ pCell->StartListeningTo(aCxt);
+ pCell->SetDirty();
+ aFormulas.push_back(pCell);
+ }
+ }
itPos = maCells.set(itPos, nRow1, aFormulas.begin(), aFormulas.end());
commit ce524556df4bf06cde1229475b9de9822a89f62b
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date: Thu Mar 13 14:43:06 2014 -0400
fdo#76132: Write test for this first.
The crash is a result of the pasted formula cell (single cell) being marked
"shared", which should never happen.
Change-Id: I7b7fa536c520c76b56cce78457e11b6e2eaee76f
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index ed5e894..c903f4f 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -3765,6 +3765,37 @@ void Test::testCopyPasteRelativeFormula()
// B2 references A2, so the value should be 1.
CPPUNIT_ASSERT_EQUAL(1.0, m_pDoc->GetValue(ScAddress(1,1,0)));
+ // Clear content and start over.
+ clearSheet(m_pDoc, 0);
+ clearSheet(&aClipDoc, 0);
+
+ // Insert a single formula cell in A1.
+ m_pDoc->SetString(ScAddress(0,0,0), "=ROW()");
+ const ScFormulaCell* pFC = m_pDoc->GetFormulaCell(ScAddress(0,0,0));
+ CPPUNIT_ASSERT(pFC);
+ CPPUNIT_ASSERT(!pFC->IsShared()); // single formula cell is never shared.
+
+ // Copy A1 to clipboard.
+ aClipParam = ScClipParam(ScAddress(0,0,0), false);
+ m_pDoc->CopyToClip(aClipParam, &aClipDoc, &aMark);
+
+ pFC = aClipDoc.GetFormulaCell(ScAddress(0,0,0));
+ CPPUNIT_ASSERT(pFC);
+ CPPUNIT_ASSERT(!pFC->IsShared());
+
+ // Paste to A3.
+ aDestRange = ScRange(0,2,0,0,2,0);
+ aMark.SetMarkArea(aDestRange);
+ m_pDoc->CopyFromClip(aDestRange, aMark, nFlags, NULL, &aClipDoc);
+
+ pFC = m_pDoc->GetFormulaCell(ScAddress(0,2,0));
+ CPPUNIT_ASSERT(pFC);
+ CPPUNIT_ASSERT(!pFC->IsShared());
+
+ // Delete A3 and make sure it doesn't crash (see fdo#76132).
+ clearRange(m_pDoc, ScAddress(0,2,0));
+ CPPUNIT_ASSERT(m_pDoc->GetCellType(ScAddress(0,2,0)) == CELLTYPE_NONE);
+
m_pDoc->DeleteTab(0);
}
More information about the Libreoffice-commits
mailing list