Underflow assert also in already calculated path

Change-Id: I7bd1c4960280a6526bb82e5b95c5253775df1e1a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147937
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Jenkins
diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
index e352f35..97c3d06 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);
        }