sc/source/core/tool/interpr4.cxx |   26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

New commits:
commit 4f7e8f0d819383a6953ccbb53f704d2265577a2f
Author:     Eike Rathke <er...@redhat.com>
AuthorDate: Mon Feb 27 23:14:01 2023 +0100
Commit:     Eike Rathke <er...@redhat.com>
CommitDate: Mon Feb 27 23:18:16 2023 +0000

    Underflow assert also in already calculated path
    
    Change-Id: I7bd1c4960280a6526bb82e5b95c5253775df1e1a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147937
    Reviewed-by: Eike Rathke <er...@redhat.com>
    Tested-by: Jenkins

diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
index e352f35a6e7b..97c3d06cdf49 100644
--- a/sc/source/core/tool/interpr4.cxx
+++ b/sc/source/core/tool/interpr4.cxx
@@ -4007,9 +4007,20 @@ StackVar ScInterpreter::Interpret()
                 (*aTokenMatrixMapIter).second->GetType() != svJumpMatrix)
         {
             // Path already calculated, reuse result.
-            nStackBase = sp - pCur->GetParamCount();
-            if ( nStackBase > sp )
-                nStackBase = sp;        // underflow?!?
+            if (sp >= pCur->GetParamCount())
+                nStackBase = sp - pCur->GetParamCount();
+            else
+            {
+                SAL_WARN("sc.core", "Stack anomaly with calculated path at "
+                        << aPos.Tab() << "," << aPos.Col() << "," << aPos.Row()
+                        << "  " << aPos.Format(
+                            ScRefFlags::VALID | ScRefFlags::FORCE_DOC | 
ScRefFlags::TAB_3D, &mrDoc)
+                        << "  eOp: " << static_cast<int>(eOp)
+                        << "  params: " << 
static_cast<int>(pCur->GetParamCount())
+                        << "  nStackBase: " << nStackBase << "  sp: " << sp);
+                nStackBase = sp;
+                assert(!"underflow");
+            }
             sp = nStackBase;
             PushTokenRef( (*aTokenMatrixMapIter).second);
         }
commit 1db24b1798b80062a1d06104828d1ec6f32ae8ec
Author:     Eike Rathke <er...@redhat.com>
AuthorDate: Mon Feb 27 18:35:49 2023 +0100
Commit:     Eike Rathke <er...@redhat.com>
CommitDate: Mon Feb 27 23:18:06 2023 +0000

    ConvertMatrixParameters() worth some asserts instead of OSL_ENSURE/OSL_FAIL
    
    Change-Id: I91e7e8d66b88912b05ff273a5eb948bb6edc504d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147928
    Reviewed-by: Eike Rathke <er...@redhat.com>
    Tested-by: Jenkins

diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
index 91f297a010db..e352f35a6e7b 100644
--- a/sc/source/core/tool/interpr4.cxx
+++ b/sc/source/core/tool/interpr4.cxx
@@ -21,6 +21,7 @@
 
 #include <interpre.hxx>
 
+#include <sal/log.hxx>
 #include <o3tl/safeint.hxx>
 #include <rtl/math.hxx>
 #include <sfx2/app.hxx>
@@ -1456,14 +1457,16 @@ void ScInterpreter::ConvertMatrixJumpConditionToMatrix()
 bool ScInterpreter::ConvertMatrixParameters()
 {
     sal_uInt16 nParams = pCur->GetParamCount();
-    OSL_ENSURE( nParams <= sp, "ConvertMatrixParameters: stack/param count 
mismatch");
+    SAL_WARN_IF( nParams > sp, "sc.core", "ConvertMatrixParameters: 
stack/param count mismatch:  eOp: "
+            << static_cast<int>(pCur->GetOpCode()) << "  sp: " << sp << "  
nParams: " << nParams);
+    assert(nParams <= sp);
     SCSIZE nJumpCols = 0, nJumpRows = 0;
     for ( sal_uInt16 i=1; i <= nParams && i <= sp; ++i )
     {
         const FormulaToken* p = pStack[ sp - i ];
         if ( p->GetOpCode() != ocPush && p->GetOpCode() != ocMissing)
         {
-            OSL_FAIL( "ConvertMatrixParameters: not a push");
+            assert(!"ConvertMatrixParameters: not a push");
         }
         else
         {
@@ -1588,7 +1591,7 @@ bool ScInterpreter::ConvertMatrixParameters()
                 }
                 break;
                 default:
-                    OSL_FAIL( "ConvertMatrixParameters: unknown parameter 
type");
+                    assert(!"ConvertMatrixParameters: unknown parameter type");
             }
         }
     }

Reply via email to