[Libreoffice-commits] core.git: formula/source include/formula sc/source
Luboš Luňák
l.lunak at collabora.com
Thu May 17 19:42:11 UTC 2018
formula/source/core/api/FormulaCompiler.cxx | 16 +++++++++++++++-
formula/source/core/api/token.cxx | 12 ++++++++++++
include/formula/FormulaCompiler.hxx | 1 +
include/formula/tokenarray.hxx | 5 +++++
sc/source/core/tool/token.cxx | 3 ++-
5 files changed, 35 insertions(+), 2 deletions(-)
New commits:
commit 30cee1ae3e36c5b3bdae71550298abac5abc8788
Author: Luboš Luňák <l.lunak at collabora.com>
Date: Mon May 14 16:23:52 2018 +0200
disable also ocStyle for Calc's threading
The ocStyle token is only in the RPN tokens, the raw tokens array contains
only ocName, so it's necessary to check also RPN tokens.
Prevents a crash with tdf#91220/1 because of ScInterpreter::ScStyle() causing
a SfxBroadcaster::Broadcast() call.
Change-Id: I7fa04114b698918569014322c721751ab3d8c62f
Reviewed-on: https://gerrit.libreoffice.org/54326
Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
Tested-by: Jenkins <ci at libreoffice.org>
diff --git a/formula/source/core/api/FormulaCompiler.cxx b/formula/source/core/api/FormulaCompiler.cxx
index 96c2e166fe00..f5e06e77deba 100644
--- a/formula/source/core/api/FormulaCompiler.cxx
+++ b/formula/source/core/api/FormulaCompiler.cxx
@@ -712,6 +712,7 @@ FormulaCompiler::FormulaCompiler( FormulaTokenArray& rArr )
bAutoCorrect( false ),
bCorrected( false ),
glSubTotal( false ),
+ needsRPNTokenCheck( false ),
mbJumpCommandReorder(true),
mbStopOnError(true)
{
@@ -734,6 +735,7 @@ FormulaCompiler::FormulaCompiler()
bAutoCorrect( false ),
bCorrected( false ),
glSubTotal( false ),
+ needsRPNTokenCheck( false ),
mbJumpCommandReorder(true),
mbStopOnError(true)
{
@@ -1328,7 +1330,14 @@ bool FormulaCompiler::GetToken()
glSubTotal = true;
break;
case ocName:
- return HandleRange();
+ if( HandleRange())
+ {
+ // Expanding ocName might have introduced tokens such as ocStyle that prevent formula threading,
+ // but those wouldn't be present in the raw tokens array, so ensure RPN tokens will be checked too.
+ needsRPNTokenCheck = true;
+ return true;
+ }
+ return false;
case ocColRowName:
return HandleColRowName();
case ocDBArea:
@@ -1980,6 +1989,7 @@ bool FormulaCompiler::CompileTokenArray()
{
glSubTotal = false;
bCorrected = false;
+ needsRPNTokenCheck = false;
if (pArr->GetCodeError() == FormulaError::NONE || !mbStopOnError)
{
if ( bAutoCorrect )
@@ -2013,7 +2023,11 @@ bool FormulaCompiler::CompileTokenArray()
while( pStack )
PopTokenArray();
if( pc )
+ {
pArr->CreateNewRPNArrayFromData( pData, pc );
+ if( needsRPNTokenCheck )
+ pArr->CheckAllRPNTokens();
+ }
// once an error, always an error
if( pArr->GetCodeError() == FormulaError::NONE && nErrorBeforePop != FormulaError::NONE )
diff --git a/formula/source/core/api/token.cxx b/formula/source/core/api/token.cxx
index 649a8d36c443..42b19f8543c0 100644
--- a/formula/source/core/api/token.cxx
+++ b/formula/source/core/api/token.cxx
@@ -674,6 +674,18 @@ void FormulaTokenArray::CheckToken( const FormulaToken& /*r*/ )
// Do nothing.
}
+void FormulaTokenArray::CheckAllRPNTokens()
+{
+ if( nRPN )
+ {
+ FormulaToken** p = pRPN;
+ for( sal_uInt16 i = 0; i < nRPN; i++ )
+ {
+ CheckToken( *p[ i ] );
+ }
+ }
+}
+
FormulaToken* FormulaTokenArray::AddToken( const FormulaToken& r )
{
return Add( r.Clone() );
diff --git a/include/formula/FormulaCompiler.hxx b/include/formula/FormulaCompiler.hxx
index e64bc867a447..321e288fcc55 100644
--- a/include/formula/FormulaCompiler.hxx
+++ b/include/formula/FormulaCompiler.hxx
@@ -354,6 +354,7 @@ protected:
bool bAutoCorrect; // whether to apply AutoCorrection
bool bCorrected; // AutoCorrection was applied
bool glSubTotal; // if code contains one or more subtotal functions
+ bool needsRPNTokenCheck; // whether to make FormulaTokenArray check all tokens at the end
bool mbJumpCommandReorder; /// Whether or not to reorder RPN for jump commands.
bool mbStopOnError; /// Whether to stop compilation on first encountered error.
diff --git a/include/formula/tokenarray.hxx b/include/formula/tokenarray.hxx
index c0376812a9fb..45669d1ad529 100644
--- a/include/formula/tokenarray.hxx
+++ b/include/formula/tokenarray.hxx
@@ -453,6 +453,11 @@ public:
*/
virtual void CheckToken( const FormulaToken& t );
+ /**
+ * Call CheckToken() for all RPN tokens.
+ */
+ void CheckAllRPNTokens();
+
/** Clones the token and then adds the clone to the pCode array.
For just new'ed tokens use Add() instead of cloning it again.
Use this AddToken() when adding a token from another origin.
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index 36b5e9f8e6e9..a973e06332cf 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -1318,7 +1318,8 @@ void ScTokenArray::CheckForThreading( OpCode eOp )
ocHLookup,
ocMatch,
ocCell,
- ocInfo
+ ocInfo,
+ ocStyle
});
// We only call this if it was already disabled
More information about the Libreoffice-commits
mailing list