sc/qa/unit/ucalc.hxx | 2 ++ sc/qa/unit/ucalc_formula.cxx | 20 ++++++++++++++++++++ sc/source/core/tool/token.cxx | 8 ++++---- 3 files changed, 26 insertions(+), 4 deletions(-)
New commits: commit 1ca0986bcc82e9fcfad055617359b619af53c794 Author: Deena Francis <deena.fran...@gmail.com> AuthorDate: Fri Dec 13 19:49:36 2019 +0530 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Mon Dec 16 08:09:01 2019 +0100 tdf#120948: row deltas should be stored as SCROW... instead of SCCOL, else it may cause overflows. Also included a unit test for protecting the fix. Change-Id: I8f735b23b7f95ecf34ccae86f00c76b82b0d668f Reviewed-on: https://gerrit.libreoffice.org/85118 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> (cherry picked from commit 3b8e554b69de349a20d10ec90b27ab71a013b464) Reviewed-on: https://gerrit.libreoffice.org/85180 diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx index d5b0bdf7ab28..777dc4a51389 100644 --- a/sc/qa/unit/ucalc.hxx +++ b/sc/qa/unit/ucalc.hxx @@ -562,6 +562,7 @@ public: void testProtectedSheetEditByColumn(); void testFuncRowsHidden(); void testInsertColCellStoreEventSwap(); + void testFormulaAfterDeleteRows(); CPPUNIT_TEST_SUITE(Test); CPPUNIT_TEST(testCollator); @@ -862,6 +863,7 @@ public: CPPUNIT_TEST(testProtectedSheetEditByColumn); CPPUNIT_TEST(testFuncRowsHidden); CPPUNIT_TEST(testInsertColCellStoreEventSwap); + CPPUNIT_TEST(testFormulaAfterDeleteRows); CPPUNIT_TEST_SUITE_END(); private: diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx index 6bbe59d067ea..c7de928a3de9 100644 --- a/sc/qa/unit/ucalc_formula.cxx +++ b/sc/qa/unit/ucalc_formula.cxx @@ -8992,4 +8992,24 @@ void Test::testInsertColCellStoreEventSwap() m_pDoc->DeleteTab(0); } +void Test::testFormulaAfterDeleteRows() +{ + sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn auto calc on. + m_pDoc->InsertTab(0, "Test"); + + // Fill A1:A70000 with 1.0 + std::vector<double> aVals(70000, 1.0); + m_pDoc->SetValues(ScAddress(0, 0, 0), aVals); + // Set A70001 with formula "=SUM(A1:A70000)" + m_pDoc->SetString(0, 70000, 0, "=SUM(A1:A70000)"); + + // Delete rows 2:69998 + m_pDoc->DeleteRow(ScRange(0, 1, 0, m_pDoc->MaxCol(), 69997, 0)); + + const ScAddress aPos(0, 3, 0); // A4 + ASSERT_FORMULA_EQUAL(*m_pDoc, aPos, "SUM(A1:A3)", "Wrong formula in A4."); + + ASSERT_DOUBLES_EQUAL_MESSAGE("Wrong value at A4", 3.0, m_pDoc->GetValue(aPos)); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx index 8bed30a6a57f..0e5a09e4e7a0 100644 --- a/sc/source/core/tool/token.cxx +++ b/sc/source/core/tool/token.cxx @@ -2837,8 +2837,8 @@ ShrinkResult shrinkRange( const sc::RefUpdateContext& rCxt, ScRange& rRefRange, else { // The reference range is truncated on the top. - SCCOL nOffset = rDeletedRange.aStart.Row() - rRefRange.aStart.Row(); - SCCOL nDelta = rRefRange.aStart.Row() - rDeletedRange.aEnd.Row() - 1; + SCROW nOffset = rDeletedRange.aStart.Row() - rRefRange.aStart.Row(); + SCROW nDelta = rRefRange.aStart.Row() - rDeletedRange.aEnd.Row() - 1; rRefRange.IncEndRowSticky(&rCxt.mrDoc, nDelta+nOffset); rRefRange.aStart.IncRow(nOffset); } @@ -2851,7 +2851,7 @@ ShrinkResult shrinkRange( const sc::RefUpdateContext& rCxt, ScRange& rRefRange, // Reference is deleted in the middle. Move the last row // position upward. - SCCOL nDelta = rDeletedRange.aStart.Row() - rDeletedRange.aEnd.Row() - 1; + SCROW nDelta = rDeletedRange.aStart.Row() - rDeletedRange.aEnd.Row() - 1; rRefRange.IncEndRowSticky(&rCxt.mrDoc, nDelta); } else @@ -2861,7 +2861,7 @@ ShrinkResult shrinkRange( const sc::RefUpdateContext& rCxt, ScRange& rRefRange, return STICKY; // The reference range is truncated on the bottom. - SCCOL nDelta = rDeletedRange.aStart.Row() - rRefRange.aEnd.Row() - 1; + SCROW nDelta = rDeletedRange.aStart.Row() - rRefRange.aEnd.Row() - 1; rRefRange.IncEndRowSticky(&rCxt.mrDoc, nDelta); } return SHRUNK; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits