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

Eike Rathke erack at redhat.com
Sat Apr 23 17:36:44 UTC 2016


 formula/source/core/api/token.cxx |    4 ++--
 include/formula/token.hxx         |    1 +
 sc/source/core/tool/interpr4.cxx  |   10 ++++------
 sc/source/core/tool/token.cxx     |    6 ++----
 4 files changed, 9 insertions(+), 12 deletions(-)

New commits:
commit 9a0735bcf984b2f23d60ee377324ddc10a49d048
Author: Eike Rathke <erack at redhat.com>
Date:   Sat Apr 23 19:29:57 2016 +0200

    SC_OPCODE_STOP_... values are exclusive
    
    ... didn't harm here though as there are gaps between sections.
    
    Change-Id: If3f4e9e5c41233dc47fde18219c8eb5bc5796d9e

diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index 00203e0..2c2f6fd 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -1565,8 +1565,7 @@ void ScTokenArray::CheckToken( const FormulaToken& r )
                 ;
         }
     }
-    else if (eOp >= SC_OPCODE_START_BIN_OP &&
-        eOp <= SC_OPCODE_STOP_UN_OP &&
+    else if (SC_OPCODE_START_BIN_OP <= eOp && eOp < SC_OPCODE_STOP_UN_OP &&
         ScInterpreter::GetGlobalConfig().mbOpenCLSubsetOnly &&
         ScInterpreter::GetGlobalConfig().mpOpenCLSubsetOpCodes->find(eOp) == ScInterpreter::GetGlobalConfig().mpOpenCLSubsetOpCodes->end())
     {
@@ -1574,8 +1573,7 @@ void ScTokenArray::CheckToken( const FormulaToken& r )
     }
     // only when openCL interpreter is not enabled - the assumption is that
     // the S/W interpreter blacklist is more strict
-    else if (eOp >= SC_OPCODE_START_BIN_OP &&
-        eOp <= SC_OPCODE_STOP_UN_OP &&
+    else if (SC_OPCODE_START_BIN_OP <= eOp && eOp < SC_OPCODE_STOP_UN_OP &&
         ScCalcConfig::isSwInterpreterEnabled() &&
         (dynamic_cast<sc::FormulaGroupInterpreterSoftware*>(sc::FormulaGroupInterpreter::getStatic()) != nullptr) &&
         ScInterpreter::GetGlobalConfig().mpSwInterpreterSubsetOpCodes->find(eOp) == ScInterpreter::GetGlobalConfig().mpSwInterpreterSubsetOpCodes->end())
commit 4f8d72d06883d29bf5c4113f8035fed8c1febae9
Author: Eike Rathke <erack at redhat.com>
Date:   Sat Apr 23 17:22:06 2016 +0200

    use FormulaToken::DeleteIfZeroRef() instead of Delete() at some places
    
    The array overflow detecting places that unconditionally deleted the
    token in case of overflow should do so only if no reference is held,
    i.e. the token was allocated with new and passed immediately without
    being assigned to a FormulaTokenRef. Just to be on the safe side.
    
    Change-Id: If2ccabec3725ac73fe82c23f51a291246847cfdb

diff --git a/formula/source/core/api/token.cxx b/formula/source/core/api/token.cxx
index ac5e339..28332ed 100644
--- a/formula/source/core/api/token.cxx
+++ b/formula/source/core/api/token.cxx
@@ -892,7 +892,7 @@ FormulaToken* FormulaTokenArray::ReplaceToken( sal_uInt16 nOffset, FormulaToken*
     }
     else
     {
-        t->Delete();
+        t->DeleteIfZeroRef();
         return nullptr;
     }
 }
@@ -912,7 +912,7 @@ FormulaToken* FormulaTokenArray::Add( FormulaToken* t )
     }
     else
     {
-        t->Delete();
+        t->DeleteIfZeroRef();
         if ( nLen == FORMULA_MAXTOKENS - 1 )
         {
             t = new FormulaByteToken( ocStop );
diff --git a/include/formula/token.hxx b/include/formula/token.hxx
index e0cd6b7..9c21ca7 100644
--- a/include/formula/token.hxx
+++ b/include/formula/token.hxx
@@ -107,6 +107,7 @@ public:
     virtual                     ~FormulaToken();
 
     inline  void                Delete()                { delete this; }
+    inline  void                DeleteIfZeroRef()       { if (mnRefCnt == 0) delete this; }
     inline  StackVar            GetType() const         { return eType; }
             bool                IsFunction() const; // pure functions, no operators
 
diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
index 570a3d0..bc2ea8d 100644
--- a/sc/source/core/tool/interpr4.cxx
+++ b/sc/source/core/tool/interpr4.cxx
@@ -663,9 +663,8 @@ void ScInterpreter::PushTempToken( FormulaToken* p )
     if ( sp >= MAXSTACK )
     {
         SetError( errStackOverflow );
-        if (!p->GetRef())
-            // p is a dangling pointer hereafter!
-            p->Delete();
+        // p may be a dangling pointer hereafter!
+        p->DeleteIfZeroRef();
     }
     else
     {
@@ -678,9 +677,8 @@ void ScInterpreter::PushTempToken( FormulaToken* p )
             }
             else
             {
-                if (!p->GetRef())
-                    // p is a dangling pointer hereafter!
-                    p->Delete();
+                // p may be a dangling pointer hereafter!
+                p->DeleteIfZeroRef();
                 PushTempTokenWithoutError( new FormulaErrorToken( nGlobalError));
             }
         }


More information about the Libreoffice-commits mailing list