[Libreoffice-commits] core.git: formula/source include/formula

Eike Rathke erack at redhat.com
Fri May 12 15:55:16 UTC 2017


 formula/source/core/api/token.cxx |   14 +++++++++++++-
 include/formula/tokenarray.hxx    |    7 ++++---
 2 files changed, 17 insertions(+), 4 deletions(-)

New commits:
commit 534746c99e88270ec766aeb12970a282a0a16520
Author: Eike Rathke <erack at redhat.com>
Date:   Fri May 12 17:48:53 2017 +0200

    Introduce and check FormulaTokenArray::mbFinalized to not add further tokens
    
    Obviously after FormulaTokenArray::Assign() or the copy-ctor for that matter,
    new tokens can not be added anymore to the shrunk code array. We don't do it,
    but ensure that it isn't done in future..
    
    Change-Id: Ibc0115f9f38e9745028a7459c61408c188783d03

diff --git a/formula/source/core/api/token.cxx b/formula/source/core/api/token.cxx
index cc5a93573fe5..63afd00cfc36 100644
--- a/formula/source/core/api/token.cxx
+++ b/formula/source/core/api/token.cxx
@@ -728,7 +728,8 @@ FormulaTokenArray::FormulaTokenArray() :
     nMode(ScRecalcMode::NORMAL),
     bHyperLink(false),
     mbFromRangeName(false),
-    mbShareable(true)
+    mbShareable(true),
+    mbFinalized(false)
 {
 }
 
@@ -752,6 +753,7 @@ void FormulaTokenArray::Assign( const FormulaTokenArray& r )
     bHyperLink = r.bHyperLink;
     mbFromRangeName = r.mbFromRangeName;
     mbShareable = r.mbShareable;
+    mbFinalized = r.mbFinalized;
     pCode  = nullptr;
     pRPN   = nullptr;
     FormulaToken** pp;
@@ -761,6 +763,7 @@ void FormulaTokenArray::Assign( const FormulaTokenArray& r )
         memcpy( pp, r.pCode, nLen * sizeof( FormulaToken* ) );
         for( sal_uInt16 i = 0; i < nLen; i++ )
             (*pp++)->IncRef();
+        mbFinalized = true;
     }
     if( nRPN )
     {
@@ -779,6 +782,7 @@ void FormulaTokenArray::Assign( sal_uInt16 nCode, FormulaToken **pTokens )
 
     nLen = nCode;
     pCode = new FormulaToken*[ nLen ];
+    mbFinalized = true;
 
     for( sal_uInt16 i = 0; i < nLen; i++ )
     {
@@ -814,6 +818,7 @@ void FormulaTokenArray::Clear()
     bHyperLink = false;
     mbFromRangeName = false;
     mbShareable = true;
+    mbFinalized = false;
     ClearRecalcMode();
 }
 
@@ -923,6 +928,13 @@ sal_uInt16 FormulaTokenArray::RemoveToken( sal_uInt16 nOffset, sal_uInt16 nCount
 
 FormulaToken* FormulaTokenArray::Add( FormulaToken* t )
 {
+    assert(!mbFinalized);
+    if (mbFinalized)
+    {
+        t->DeleteIfZeroRef();
+        return nullptr;
+    }
+
     if( !pCode )
         pCode = new FormulaToken*[ FORMULA_MAXTOKENS ];
     if( nLen < FORMULA_MAXTOKENS - 1 )
diff --git a/include/formula/tokenarray.hxx b/include/formula/tokenarray.hxx
index 39e326b63ade..f7a8228a0d0e 100644
--- a/include/formula/tokenarray.hxx
+++ b/include/formula/tokenarray.hxx
@@ -125,9 +125,10 @@ protected:
     sal_uInt16      nIndex;                 // Current step index
     FormulaError    nError;                 // Error code
     ScRecalcMode    nMode;                  // Flags to indicate when to recalc this code
-    bool            bHyperLink;             // If HYPERLINK() occurs in the formula.
-    bool            mbFromRangeName;        // If this array originates from a named expression
-    bool            mbShareable;            // Whether or not it can be shared with adjacent cells.
+    bool            bHyperLink      :1;     // If HYPERLINK() occurs in the formula.
+    bool            mbFromRangeName :1;     // If this array originates from a named expression
+    bool            mbShareable     :1;     // Whether or not it can be shared with adjacent cells.
+    bool            mbFinalized     :1;     // Whether code arrays have their final used size and no more tokens can be added.
 
 protected:
     void                    Assign( const FormulaTokenArray& );


More information about the Libreoffice-commits mailing list