[Libreoffice-commits] core.git: Branch 'libreoffice-6-2' - sc/source
Luboš Luňák (via logerrit)
logerrit at kemper.freedesktop.org
Thu Mar 28 13:42:05 UTC 2019
sc/source/core/data/simpleformulacalc.cxx | 10 ++++++----
sc/source/core/tool/interpr1.cxx | 23 +++++++++++++----------
2 files changed, 19 insertions(+), 14 deletions(-)
New commits:
commit e68e9b2d61376b989bd4f61d38b7e06d0ee591cb
Author: Luboš Luňák <l.lunak at collabora.com>
AuthorDate: Tue Mar 12 15:41:46 2019 +0100
Commit: Xisco Faulí <xiscofauli at libreoffice.org>
CommitDate: Thu Mar 28 14:41:41 2019 +0100
avoid a crash with an editor-forced matrix formula (tdf#123479)
Normally when ScInterpreter has bMatrixFormula set, pMyFormulaCell
is set as well (done in the ctor). But in some rare cases,
this may not be so, and some functions such as ScRandom() already
check for this. But not all do, tdf#123479 specifically crashes
because ec97496525f82f added AssertFormulaMatrix() to force
bMatrixFormula be set without pMyFormulaCell being set, and ScColumn()
doesn't handle this case.
Fix this by trying to pass ScFormulaCell* to ScInterpreter when
AssertFormulaMatrix() is used, this should ensure the result
in the formula editor fits better the edited formula. Since there
still may be cases when the cell is not set (e.g. editing a new
formula), also handle that case gracefully.
Ideally ScSimpleFormulaCalculator should pass ScMarkData to ScInterpreter
in such cases so that those functions use that when they can't use
GetMatColsRows(), but currently the handling of selections is rather
poor in the formula edit dialog: Non-array formulas are simply entered
in one cell and the selection is ignored, in case of a multi-selection
there's an error dialog only after the dialog is closed, and the result
field of the dialog is rather small and doesn't scroll, so e.g. matrix
result of ScRandom() wouldn't show more than one item anyway. Given that
tdf#123479 is a priority bug, better just fix it and possibly handle
selections better somewhen later.
Change-Id: I5fcbe1e358fac3623d4917eb0ead8eae00a1e153
Reviewed-on: https://gerrit.libreoffice.org/69161
Reviewed-by: Dennis Francis <dennis.francis at collabora.com>
Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>
Tested-by: Luboš Luňák <l.lunak at collabora.com>
(cherry picked from commit ade1df0948563b532a5d293c31d46a4f042559ee)
Reviewed-on: https://gerrit.libreoffice.org/69849
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak at collabora.com>
Reviewed-by: Xisco Faulí <xiscofauli at libreoffice.org>
diff --git a/sc/source/core/data/simpleformulacalc.cxx b/sc/source/core/data/simpleformulacalc.cxx
index 3ed2c173f3c6..972f5091cad5 100644
--- a/sc/source/core/data/simpleformulacalc.cxx
+++ b/sc/source/core/data/simpleformulacalc.cxx
@@ -45,14 +45,14 @@ void ScSimpleFormulaCalculator::Calculate()
return;
mbCalculated = true;
- ScInterpreter aInt(nullptr, mpDoc, mpDoc->GetNonThreadedContext(), maAddr, *mpCode);
-
- std::unique_ptr<sfx2::LinkManager> pNewLinkMgr( new sfx2::LinkManager(mpDoc->GetDocumentShell()) );
- aInt.SetLinkManager( pNewLinkMgr.get() );
+ ScInterpreter aInt(mpDoc->GetFormulaCell( maAddr ), mpDoc, mpDoc->GetNonThreadedContext(), maAddr, *mpCode);
if (mbMatrixFormula)
aInt.AssertFormulaMatrix();
+ std::unique_ptr<sfx2::LinkManager> pNewLinkMgr( new sfx2::LinkManager(mpDoc->GetDocumentShell()) );
+ aInt.SetLinkManager( pNewLinkMgr.get() );
+
formula::StackVar aIntType = aInt.Interpret();
if ( aIntType == formula::svMatrixCell )
{
@@ -94,6 +94,8 @@ bool ScSimpleFormulaCalculator::IsValue()
bool ScSimpleFormulaCalculator::IsMatrix()
{
+ Calculate();
+
return mbMatrixResult;
}
diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index fc0600368b7f..e7d00deb6aac 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -1738,11 +1738,12 @@ void ScInterpreter::ScPi()
void ScInterpreter::ScRandom()
{
- if (bMatrixFormula && pMyFormulaCell)
+ if (bMatrixFormula)
{
- SCCOL nCols;
- SCROW nRows;
- pMyFormulaCell->GetMatColsRows( nCols, nRows);
+ SCCOL nCols = 0;
+ SCROW nRows = 0;
+ if(pMyFormulaCell)
+ pMyFormulaCell->GetMatColsRows( nCols, nRows);
// ScViewFunc::EnterMatrix() might be asking for
// ScFormulaCell::GetResultDimensions(), which here are none so create
// a 1x1 matrix at least which exactly is the case when EnterMatrix()
@@ -4385,9 +4386,10 @@ void ScInterpreter::ScColumn()
nVal = aPos.Col() + 1;
if (bMatrixFormula)
{
- SCCOL nCols;
- SCROW nRows;
- pMyFormulaCell->GetMatColsRows( nCols, nRows);
+ SCCOL nCols = 0;
+ SCROW nRows = 0;
+ if (pMyFormulaCell)
+ pMyFormulaCell->GetMatColsRows( nCols, nRows);
if (nCols == 0)
{
// Happens if called via ScViewFunc::EnterMatrix()
@@ -4488,9 +4490,10 @@ void ScInterpreter::ScRow()
nVal = aPos.Row() + 1;
if (bMatrixFormula)
{
- SCCOL nCols;
- SCROW nRows;
- pMyFormulaCell->GetMatColsRows( nCols, nRows);
+ SCCOL nCols = 0;
+ SCROW nRows = 0;
+ if (pMyFormulaCell)
+ pMyFormulaCell->GetMatColsRows( nCols, nRows);
if (nRows == 0)
{
// Happens if called via ScViewFunc::EnterMatrix()
More information about the Libreoffice-commits
mailing list