sc/qa/unit/uicalc/uicalc.cxx | 8 ++++- sc/source/core/tool/interpr1.cxx | 58 ++++++++++++++++++++++----------------- 2 files changed, 40 insertions(+), 26 deletions(-)
New commits: commit 5eb23da4c4a6ba6c35142918d0313432365b8e51 Author: Eike Rathke <er...@redhat.com> AuthorDate: Tue Jun 30 23:08:31 2020 +0200 Commit: Eike Rathke <er...@redhat.com> CommitDate: Wed Jul 1 12:41:44 2020 +0200 Resolves: tdf#85551 OFFSET() NewWidth and NewHeight must be >0 if given This also makes it necessary to adjust a test that reused the bug document for a different scenario but checked the result. Change-Id: I80136747445d5029aa5c894270448f002c567e3c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97553 Reviewed-by: Eike Rathke <er...@redhat.com> Tested-by: Jenkins (cherry picked from commit f31d8d61859bb375c99419ff176adca27a9197b6) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97509 diff --git a/sc/qa/unit/uicalc/uicalc.cxx b/sc/qa/unit/uicalc/uicalc.cxx index 694644b77df3..b68c5e6cd941 100644 --- a/sc/qa/unit/uicalc/uicalc.cxx +++ b/sc/qa/unit/uicalc/uicalc.cxx @@ -123,14 +123,18 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf124816) ScDocument* pDoc = pModelObj->GetDocument(); CPPUNIT_ASSERT(pDoc); + // The actual result is completely unrelated to this test and behaviour of + // OFFSET() was changed as of tdf#85551 and here result of that test + // document is now Err:502 instead of 0. + const OUString aExpectedResult("Err:502"); checkCurrentCell(3, 9); - CPPUNIT_ASSERT_EQUAL(OUString("0"), pDoc->GetString(ScAddress(3, 9, 0))); + CPPUNIT_ASSERT_EQUAL(aExpectedResult, pDoc->GetString(ScAddress(3, 9, 0))); //Without the fix, it would crash dispatchCommand(mxComponent, ".uno:InsertRowsBefore", {}); CPPUNIT_ASSERT_EQUAL(OUString(""), pDoc->GetString(ScAddress(3, 9, 0))); dispatchCommand(mxComponent, ".uno:Undo", {}); - CPPUNIT_ASSERT_EQUAL(OUString("0"), pDoc->GetString(ScAddress(3, 9, 0))); + CPPUNIT_ASSERT_EQUAL(aExpectedResult, pDoc->GetString(ScAddress(3, 9, 0))); } CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf124815) diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx index d4f134fa0b19..8af767c9b00e 100644 --- a/sc/source/core/tool/interpr1.cxx +++ b/sc/source/core/tool/interpr1.cxx @@ -8319,35 +8319,53 @@ void ScInterpreter::ScOffset() sal_uInt8 nParamCount = GetByte(); if ( MustHaveParamCount( nParamCount, 3, 5 ) ) { - sal_Int32 nColNew = -1, nRowNew = -1, nColPlus, nRowPlus; + bool bNewWidth = false; + bool bNewHeight = false; + sal_Int32 nColNew = 1, nRowNew = 1; if (nParamCount == 5) - nColNew = GetInt32(); + { + if (IsMissing()) + PopError(); + else + { + nColNew = GetInt32(); + bNewWidth = true; + } + } if (nParamCount >= 4) - nRowNew = GetInt32WithDefault(-1); - nColPlus = GetInt32(); - nRowPlus = GetInt32(); + { + if (IsMissing()) + PopError(); + else + { + nRowNew = GetInt32(); + bNewHeight = true; + } + } + sal_Int32 nColPlus = GetInt32(); + sal_Int32 nRowPlus = GetInt32(); if (nGlobalError != FormulaError::NONE) { PushError( nGlobalError); return; } + if (nColNew <= 0 || nRowNew <= 0) + { + PushIllegalArgument(); + return; + } SCCOL nCol1(0); SCROW nRow1(0); SCTAB nTab1(0); SCCOL nCol2(0); SCROW nRow2(0); SCTAB nTab2(0); - if (nColNew == 0 || nRowNew == 0) - { - PushIllegalArgument(); - return; - } switch (GetStackType()) { case svSingleRef: { PopSingleRef(nCol1, nRow1, nTab1); - if (nParamCount == 3 || (nColNew < 0 && nRowNew < 0)) + if (!bNewWidth && !bNewHeight) { nCol1 = static_cast<SCCOL>(static_cast<long>(nCol1) + nColPlus); nRow1 = static_cast<SCROW>(static_cast<long>(nRow1) + nRowPlus); @@ -8358,10 +8376,6 @@ void ScInterpreter::ScOffset() } else { - if (nColNew < 0) - nColNew = 1; - if (nRowNew < 0) - nRowNew = 1; nCol1 = static_cast<SCCOL>(static_cast<long>(nCol1)+nColPlus); nRow1 = static_cast<SCROW>(static_cast<long>(nRow1)+nRowPlus); nCol2 = static_cast<SCCOL>(static_cast<long>(nCol1)+nColNew-1); @@ -8385,7 +8399,7 @@ void ScInterpreter::ScOffset() nRow1 = aAbsRef.Row(); nTab1 = aAbsRef.Tab(); - if (nParamCount == 3 || (nColNew < 0 && nRowNew < 0)) + if (!bNewWidth && !bNewHeight) { nCol1 = static_cast<SCCOL>(static_cast<long>(nCol1) + nColPlus); nRow1 = static_cast<SCROW>(static_cast<long>(nRow1) + nRowPlus); @@ -8396,10 +8410,6 @@ void ScInterpreter::ScOffset() } else { - if (nColNew < 0) - nColNew = 1; - if (nRowNew < 0) - nRowNew = 1; nCol1 = static_cast<SCCOL>(static_cast<long>(nCol1)+nColPlus); nRow1 = static_cast<SCROW>(static_cast<long>(nRow1)+nRowPlus); nCol2 = static_cast<SCCOL>(static_cast<long>(nCol1)+nColNew-1); @@ -8416,9 +8426,9 @@ void ScInterpreter::ScOffset() case svDoubleRef: { PopDoubleRef(nCol1, nRow1, nTab1, nCol2, nRow2, nTab2); - if (nColNew < 0) + if (!bNewWidth) nColNew = nCol2 - nCol1 + 1; - if (nRowNew < 0) + if (!bNewHeight) nRowNew = nRow2 - nRow1 + 1; nCol1 = static_cast<SCCOL>(static_cast<long>(nCol1)+nColPlus); nRow1 = static_cast<SCROW>(static_cast<long>(nRow1)+nRowPlus); @@ -8444,9 +8454,9 @@ void ScInterpreter::ScOffset() nCol2 = aAbs.aEnd.Col(); nRow2 = aAbs.aEnd.Row(); nTab2 = aAbs.aEnd.Tab(); - if (nColNew < 0) + if (!bNewWidth) nColNew = nCol2 - nCol1 + 1; - if (nRowNew < 0) + if (!bNewHeight) nRowNew = nRow2 - nRow1 + 1; nCol1 = static_cast<SCCOL>(static_cast<long>(nCol1)+nColPlus); nRow1 = static_cast<SCROW>(static_cast<long>(nRow1)+nRowPlus); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits