[Libreoffice-commits] core.git: sc/source
Luboš Luňák (via logerrit)
logerrit at kemper.freedesktop.org
Mon Mar 25 09:54:12 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 ade1df0948563b532a5d293c31d46a4f042559ee
Author: Luboš Luňák <l.lunak at collabora.com>
AuthorDate: Tue Mar 12 15:41:46 2019 +0100
Commit: Luboš Luňák <l.lunak at collabora.com>
CommitDate: Mon Mar 25 10:53:51 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>
diff --git a/sc/source/core/data/simpleformulacalc.cxx b/sc/source/core/data/simpleformulacalc.cxx
index f32f77a2ab0e..d6080281525d 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 0281ab3f4cbf..e94bdab3f25b 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -1733,11 +1733,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()
@@ -4380,9 +4381,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()
@@ -4483,9 +4485,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