[Libreoffice-commits] core.git: sc/qa sc/source
Eike Rathke (via logerrit)
logerrit at kemper.freedesktop.org
Wed Jul 1 00:49:58 UTC 2020
sc/qa/unit/uicalc/uicalc.cxx | 8 ++++-
sc/source/core/tool/interpr1.cxx | 58 ++++++++++++++++++++++-----------------
2 files changed, 40 insertions(+), 26 deletions(-)
New commits:
commit af9ed183399d68c42a66382ecf32f402403340ff
Author: Eike Rathke <erack at redhat.com>
AuthorDate: Tue Jun 30 23:08:31 2020 +0200
Commit: Eike Rathke <erack at redhat.com>
CommitDate: Wed Jul 1 02:49:13 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 <erack at redhat.com>
Tested-by: Jenkins
diff --git a/sc/qa/unit/uicalc/uicalc.cxx b/sc/qa/unit/uicalc/uicalc.cxx
index 84b16529c864..e93ac339ae76 100644
--- a/sc/qa/unit/uicalc/uicalc.cxx
+++ b/sc/qa/unit/uicalc/uicalc.cxx
@@ -180,14 +180,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 419ae159a64b..9312a2a1eea1 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);
More information about the Libreoffice-commits
mailing list