[Libreoffice-commits] .: filter/source sc/source starmath/source vcl/source

Eike Rathke erack at kemper.freedesktop.org
Wed Dec 7 08:29:20 PST 2011


 filter/source/svg/svgwriter.hxx     |    9 +-
 sc/source/core/tool/chgtrack.cxx    |    9 ++
 sc/source/filter/xcl97/xcl97esc.cxx |   14 +++-
 sc/source/filter/xml/xmlfilti.hxx   |   10 ++
 starmath/source/mathmlimport.cxx    |   94 +++++++++++----------------
 starmath/source/mathmlimport.hxx    |    2 
 starmath/source/parse.cxx           |  124 ++++++++++++++----------------------
 vcl/source/gdi/cvtsvm.cxx           |   20 ++++-
 8 files changed, 140 insertions(+), 142 deletions(-)

New commits:
commit cabf25372cf98869616c3d583eb99fa5f5eb3a8f
Author: Eike Rathke <erack at redhat.com>
Date:   Wed Dec 7 16:11:57 2011 +0100

    old class Stack pop'ed 0 from empty stack, which std::stack doesn't
    
    Some places in the code assumed that if the stack is empty a null pointer is
    returned by top() (or old Pop()), this doesn't work anymore with ::std::stack
    that instead has undefined behavior in that case, so check !stack.empty()
    first before accessing top.
    (cherry picked from commit ac40f7d6503533954127e818f2bf009200c1e3f2)

diff --git a/filter/source/svg/svgwriter.hxx b/filter/source/svg/svgwriter.hxx
index 0b6048e..b4fe4ae 100644
--- a/filter/source/svg/svgwriter.hxx
+++ b/filter/source/svg/svgwriter.hxx
@@ -186,9 +186,12 @@ private:
     }
     void                    ImplReleaseContext()
     {
-        delete maContextStack.top();
-        maContextStack.pop();
-        mpContext = maContextStack.top();
+        if (!maContextStack.empty())
+        {
+            delete maContextStack.top();
+            maContextStack.pop();
+        }
+        mpContext = (maContextStack.empty() ? NULL : maContextStack.top());
     }
 
     long                    ImplMap( sal_Int32 nVal ) const;
diff --git a/sc/source/core/tool/chgtrack.cxx b/sc/source/core/tool/chgtrack.cxx
index a94b0d3..7a85014 100644
--- a/sc/source/core/tool/chgtrack.cxx
+++ b/sc/source/core/tool/chgtrack.cxx
@@ -2240,8 +2240,13 @@ void ScChangeTrack::EndBlockModify( sal_uLong nEndAction )
             }
             else
                 delete pBlockModifyMsg;
-            pBlockModifyMsg = aMsgStackTmp.top();   // evtl. Block im Block
-            aMsgStackTmp.pop();
+            if (aMsgStackTmp.empty())
+                pBlockModifyMsg = NULL;
+            else
+            {
+                pBlockModifyMsg = aMsgStackTmp.top();   // evtl. Block im Block
+                aMsgStackTmp.pop();
+            }
         }
         if ( !pBlockModifyMsg )
         {
diff --git a/sc/source/filter/xcl97/xcl97esc.cxx b/sc/source/filter/xcl97/xcl97esc.cxx
index 207a37d..50b53c2 100644
--- a/sc/source/filter/xcl97/xcl97esc.cxx
+++ b/sc/source/filter/xcl97/xcl97esc.cxx
@@ -346,9 +346,17 @@ void XclEscherEx::EndShape( sal_uInt16 nShapeType, sal_uInt32 nShapeID )
 
     // get next object from stack
     DeleteCurrAppData();
-    pCurrXclObj = aStack.top().first;
-    pCurrAppData = aStack.top().second;
-    aStack.pop();
+    if (aStack.empty())
+    {
+        pCurrXclObj = NULL;
+        pCurrAppData = NULL;
+    }
+    else
+    {
+        pCurrXclObj = aStack.top().first;
+        pCurrAppData = aStack.top().second;
+        aStack.pop();
+    }
     if( nAdditionalText == 3 )
         nAdditionalText = 0;
 }
diff --git a/sc/source/filter/xml/xmlfilti.hxx b/sc/source/filter/xml/xmlfilti.hxx
index bb30101..759f954 100644
--- a/sc/source/filter/xml/xmlfilti.hxx
+++ b/sc/source/filter/xml/xmlfilti.hxx
@@ -262,8 +262,14 @@ public:
 
     void CloseConnection()
     {
-        bool bTemp = aConnectionOrStack.top();
-        aConnectionOrStack.pop();
+        bool bTemp;
+        if (aConnectionOrStack.empty())
+            bTemp = false;
+        else
+        {
+            bTemp = aConnectionOrStack.top();
+            aConnectionOrStack.pop();
+        }
         bConnectionOr = bTemp;
         bNextConnectionOr = bTemp;
     }
diff --git a/starmath/source/mathmlimport.cxx b/starmath/source/mathmlimport.cxx
index 0db8cc4..9290127 100644
--- a/starmath/source/mathmlimport.cxx
+++ b/starmath/source/mathmlimport.cxx
@@ -95,6 +95,18 @@ using ::rtl::OUStringBuffer;
 
 ////////////////////////////////////////////////////////////
 
+namespace {
+template < typename T >
+T* lcl_popOrZero( ::std::stack<T*> & rStack )
+{
+    if (rStack.empty())
+        return 0;
+    T* pTmp = rStack.top();
+    rStack.pop();
+    return pTmp;
+}
+}
+
 sal_uLong SmXMLImportWrapper::Import(SfxMedium &rMedium)
 {
     sal_uLong nError = ERRCODE_SFX_DOLOADFAILED;
@@ -747,8 +759,7 @@ void SmXMLContext_Helper::ApplyAttrs()
                 aToken.eType = TNBOLD;
             SmStructureNode *pFontNode = static_cast<SmStructureNode *>
                 (new SmFontNode(aToken));
-            pFontNode->SetSubNodes(0,rNodeStack.top());
-            rNodeStack.pop();
+            pFontNode->SetSubNodes(0,lcl_popOrZero(rNodeStack));
             rNodeStack.push(pFontNode);
         }
         if (nIsItalic != -1)
@@ -759,8 +770,7 @@ void SmXMLContext_Helper::ApplyAttrs()
                 aToken.eType = TNITALIC;
             SmStructureNode *pFontNode = static_cast<SmStructureNode *>
                 (new SmFontNode(aToken));
-            pFontNode->SetSubNodes(0,rNodeStack.top());
-            rNodeStack.pop();
+            pFontNode->SetSubNodes(0,lcl_popOrZero(rNodeStack));
             rNodeStack.push(pFontNode);
         }
         if (nFontSize != 0.0)
@@ -781,8 +791,7 @@ void SmXMLContext_Helper::ApplyAttrs()
             else
                 pFontNode->SetSizeParameter(Fraction(nFontSize),FNTSIZ_ABSOLUT);
 
-            pFontNode->SetSubNodes(0,rNodeStack.top());
-            rNodeStack.pop();
+            pFontNode->SetSubNodes(0,lcl_popOrZero(rNodeStack));
             rNodeStack.push(pFontNode);
         }
         if (sFontFamily.getLength())
@@ -801,8 +810,7 @@ void SmXMLContext_Helper::ApplyAttrs()
 
             aToken.aText = sFontFamily;
             SmFontNode *pFontNode = new SmFontNode(aToken);
-            pFontNode->SetSubNodes(0,rNodeStack.top());
-            rNodeStack.pop();
+            pFontNode->SetSubNodes(0,lcl_popOrZero(rNodeStack));
             rNodeStack.push(pFontNode);
         }
         if (sColor.getLength())
@@ -816,8 +824,7 @@ void SmXMLContext_Helper::ApplyAttrs()
             if (aToken.eType != -1)
             {
                 SmFontNode *pFontNode = new SmFontNode(aToken);
-                pFontNode->SetSubNodes(0,rNodeStack.top());
-                rNodeStack.pop();
+                pFontNode->SetSubNodes(0,lcl_popOrZero(rNodeStack));
                 rNodeStack.push(pFontNode);
             }
         }
@@ -991,8 +998,7 @@ void SmXMLPhantomContext_Impl::EndElement()
     SmStructureNode *pPhantom = static_cast<SmStructureNode *>
         (new SmFontNode(aToken));
     SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
-    pPhantom->SetSubNodes(0,rNodeStack.top());
-    rNodeStack.pop();
+    pPhantom->SetSubNodes(0,lcl_popOrZero(rNodeStack));
     rNodeStack.push(pPhantom);
 }
 
@@ -1482,10 +1488,8 @@ void SmXMLSubContext_Impl::GenericEndElement(SmTokenType eType, SmSubSup eSubSup
     for (sal_uLong i = 1;  i < aSubNodes.size();  i++)
         aSubNodes[i] = NULL;
 
-    aSubNodes[eSubSup+1] = rNodeStack.top();
-    rNodeStack.pop();
-    aSubNodes[0] = rNodeStack.top();
-    rNodeStack.pop();
+    aSubNodes[eSubSup+1] = lcl_popOrZero(rNodeStack);
+    aSubNodes[0] = lcl_popOrZero(rNodeStack);
     pNode->SetSubNodes(aSubNodes);
     rNodeStack.push(pNode);
 }
@@ -1546,12 +1550,9 @@ void SmXMLSubSupContext_Impl::GenericEndElement(SmTokenType eType,
     for (sal_uLong i = 1;  i < aSubNodes.size();  i++)
         aSubNodes[i] = NULL;
 
-    aSubNodes[aSup+1] = rNodeStack.top();
-    rNodeStack.pop();
-    aSubNodes[aSub+1] = rNodeStack.top();
-    rNodeStack.pop();
-    aSubNodes[0] =  rNodeStack.top();
-    rNodeStack.pop();
+    aSubNodes[aSup+1] = lcl_popOrZero(rNodeStack);
+    aSubNodes[aSub+1] = lcl_popOrZero(rNodeStack);
+    aSubNodes[0] =  lcl_popOrZero(rNodeStack);
     pNode->SetSubNodes(aSubNodes);
     rNodeStack.push(pNode);
 }
@@ -1588,8 +1589,7 @@ void SmXMLUnderContext_Impl::HandleAccent()
 
     /*Just one special case for the underline thing*/
     SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
-    SmNode *pTest = rNodeStack.top();
-    rNodeStack.pop();
+    SmNode *pTest = lcl_popOrZero(rNodeStack);
     SmToken aToken;
     aToken.cMathChar = '\0';
     aToken.nGroup = 0;
@@ -1609,8 +1609,7 @@ void SmXMLUnderContext_Impl::HandleAccent()
     else
         aSubNodes[0] = pTest;
 
-    aSubNodes[1] = rNodeStack.top();
-    rNodeStack.pop();
+    aSubNodes[1] = lcl_popOrZero(rNodeStack);
     pNode->SetSubNodes(aSubNodes);
     pNode->SetScaleMode(SCALE_WIDTH);
     rNodeStack.push(pNode);
@@ -1677,10 +1676,8 @@ void SmXMLOverContext_Impl::HandleAccent()
 
     SmNodeArray aSubNodes;
     aSubNodes.resize(2);
-    aSubNodes[0] = rNodeStack.top();
-    rNodeStack.pop();
-    aSubNodes[1] = rNodeStack.top();
-    rNodeStack.pop();
+    aSubNodes[0] = lcl_popOrZero(rNodeStack);
+    aSubNodes[1] = lcl_popOrZero(rNodeStack);
     pNode->SetSubNodes(aSubNodes);
     pNode->SetScaleMode(SCALE_WIDTH);
     rNodeStack.push(pNode);
@@ -2194,11 +2191,7 @@ void SmXMLDocContext_Impl::EndElement()
     ContextArray.resize(1);
     SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
 
-    for (sal_uLong i=0;i< 1;i++)
-    {
-        ContextArray[i] = rNodeStack.top();
-        rNodeStack.pop();
-    }
+    ContextArray[0] = lcl_popOrZero(rNodeStack);
 
     SmToken aDummy;
     SmStructureNode *pSNode = new SmLineNode(aDummy);
@@ -2233,10 +2226,8 @@ void SmXMLFracContext_Impl::EndElement()
     aToken.eType = TOVER;
     SmStructureNode *pSNode = new SmBinVerNode(aToken);
     SmNode *pOper = new SmRectangleNode(aToken);
-    SmNode *pSecond = rNodeStack.top();
-    rNodeStack.pop();
-    SmNode *pFirst = rNodeStack.top();
-    rNodeStack.pop();
+    SmNode *pSecond = lcl_popOrZero(rNodeStack);
+    SmNode *pFirst = lcl_popOrZero(rNodeStack);
     pSNode->SetSubNodes(pFirst,pOper,pSecond);
     rNodeStack.push(pSNode);
 }
@@ -2257,10 +2248,8 @@ void SmXMLRootContext_Impl::EndElement()
     SmStructureNode *pSNode = new SmRootNode(aToken);
     SmNode *pOper = new SmRootSymbolNode(aToken);
     SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
-    SmNode *pIndex = rNodeStack.top();
-    rNodeStack.pop();
-    SmNode *pBase = rNodeStack.top();
-    rNodeStack.pop();
+    SmNode *pIndex = lcl_popOrZero(rNodeStack);
+    SmNode *pBase = lcl_popOrZero(rNodeStack);
     pSNode->SetSubNodes(pIndex,pOper,pBase);
     rNodeStack.push(pSNode);
 }
@@ -2283,8 +2272,7 @@ void SmXMLSqrtContext_Impl::EndElement()
     SmStructureNode *pSNode = new SmRootNode(aToken);
     SmNode *pOper = new SmRootSymbolNode(aToken);
     SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
-    pSNode->SetSubNodes(0,pOper,rNodeStack.top());
-    rNodeStack.pop();
+    pSNode->SetSubNodes(0,pOper,lcl_popOrZero(rNodeStack));
     rNodeStack.push(pSNode);
 }
 
@@ -2297,7 +2285,7 @@ void SmXMLRowContext_Impl::EndElement()
     if (nSize > 0)
     {
         aRelationArray.resize(nSize);
-        for (sal_uLong j=rNodeStack.size()-nElementCount;j > 0;j--)
+        for (sal_uLong j=nSize;j > 0;j--)
         {
             aRelationArray[j-1] = rNodeStack.top();
             rNodeStack.pop();
@@ -2525,17 +2513,14 @@ void SmXMLMultiScriptsContext_Impl::ProcessSubSupPairs(bool bIsPrescript)
             /*On each loop the base and its sub sup pair becomes the
              base for the next loop to which the next sub sup pair is
              attached, i.e. wheels within wheels*/
-            aSubNodes[0] = aReverseStack.top();
-            aReverseStack.pop();
+            aSubNodes[0] = lcl_popOrZero(aReverseStack);
 
-            SmNode *pScriptNode = aReverseStack.top();
-            aReverseStack.pop();
+            SmNode *pScriptNode = lcl_popOrZero(aReverseStack);
 
             if (pScriptNode && ((pScriptNode->GetToken().eType != TIDENT) ||
                 (pScriptNode->GetToken().aText.Len())))
                 aSubNodes[eSub+1] = pScriptNode;
-            pScriptNode = aReverseStack.top();
-            aReverseStack.pop();
+            pScriptNode = lcl_popOrZero(aReverseStack);
             if (pScriptNode && ((pScriptNode->GetToken().eType != TIDENT) ||
                 (pScriptNode->GetToken().aText.Len())))
                 aSubNodes[eSup+1] = pScriptNode;
@@ -2543,8 +2528,7 @@ void SmXMLMultiScriptsContext_Impl::ProcessSubSupPairs(bool bIsPrescript)
             pNode->SetSubNodes(aSubNodes);
             aReverseStack.push(pNode);
         }
-        rNodeStack.push(aReverseStack.top());
-        aReverseStack.pop();
+        rNodeStack.push(lcl_popOrZero(aReverseStack));
     }
     else
     {
@@ -2569,7 +2553,7 @@ void SmXMLTableContext_Impl::EndElement()
     sal_uInt16 nCols = 0;
 
     SmStructureNode *pArray;
-    for (sal_uLong i=rNodeStack.size()-nElementCount;i > 0;i--)
+    for (sal_uLong i=nRows;i > 0;i--)
     {
         pArray = (SmStructureNode *)rNodeStack.top();
         rNodeStack.pop();
diff --git a/starmath/source/mathmlimport.hxx b/starmath/source/mathmlimport.hxx
index 5ed8096..e67e6a0 100644
--- a/starmath/source/mathmlimport.hxx
+++ b/starmath/source/mathmlimport.hxx
@@ -254,6 +254,8 @@ public:
     SmNodeStack & GetNodeStack()    { return aNodeStack; }
     SmNode *GetTree()
     {
+        if (aNodeStack.empty())
+            return 0;
         SmNode* result = aNodeStack.top();
         aNodeStack.pop();
         return result;
diff --git a/starmath/source/parse.cxx b/starmath/source/parse.cxx
index 7a2741f..34425ab 100644
--- a/starmath/source/parse.cxx
+++ b/starmath/source/parse.cxx
@@ -51,6 +51,18 @@ using namespace ::com::sun::star::i18n;
 
 ///////////////////////////////////////////////////////////////////////////
 
+namespace {
+template < typename T >
+T* lcl_popOrZero( ::std::stack<T*> & rStack )
+{
+    if (rStack.empty())
+        return 0;
+    T* pTmp = rStack.top();
+    rStack.pop();
+    return pTmp;
+}
+}
+
 static inline bool strnccmp(const String &u1, xub_StrLen nIdx,
                               const sal_Char *s2, xub_StrLen nLen)
 {
@@ -1066,8 +1078,7 @@ void SmParser::Align()
 
     if (pSNode)
     {
-        pSNode->SetSubNodes(m_aNodeStack.top(), 0);
-        m_aNodeStack.pop();
+        pSNode->SetSubNodes(lcl_popOrZero(m_aNodeStack), 0);
         m_aNodeStack.push(pSNode);
     }
 }
@@ -1086,8 +1097,7 @@ void SmParser::Line()
     if (m_aCurToken.eType != TEND  &&  m_aCurToken.eType != TNEWLINE)
     {   Align();
         ExpressionArray.resize(++n);
-        ExpressionArray[n - 1] = m_aNodeStack.top();
-        m_aNodeStack.pop();
+        ExpressionArray[n - 1] = lcl_popOrZero(m_aNodeStack);
     }
 
     while (m_aCurToken.eType != TEND  &&  m_aCurToken.eType != TNEWLINE)
@@ -1096,8 +1106,7 @@ void SmParser::Line()
         else
             Align();
         ExpressionArray.resize(++n);
-        ExpressionArray[n - 1] = m_aNodeStack.top();
-        m_aNodeStack.pop();
+        ExpressionArray[n - 1] = lcl_popOrZero(m_aNodeStack);
     }
 
     //If there's no expression, add an empty one.
@@ -1132,14 +1141,12 @@ void SmParser::Expression()
 
     Relation();
     RelationArray.resize(++n);
-    RelationArray[n - 1] = m_aNodeStack.top();
-    m_aNodeStack.pop();
+    RelationArray[n - 1] = lcl_popOrZero(m_aNodeStack);
 
     while (m_aCurToken.nLevel >= 4)
     {   Relation();
         RelationArray.resize(++n);
-        RelationArray[n - 1] = m_aNodeStack.top();
-        m_aNodeStack.pop();
+        RelationArray[n - 1] = lcl_popOrZero(m_aNodeStack);
     }
 
     SmExpressionNode *pSNode = new SmExpressionNode(m_aCurToken);
@@ -1155,17 +1162,14 @@ void SmParser::Relation()
     while (TokenInGroup(TGRELATION))
     {
         SmStructureNode *pSNode  = new SmBinHorNode(m_aCurToken);
-        SmNode *pFirst = m_aNodeStack.top();
-        m_aNodeStack.pop();
+        SmNode *pFirst = lcl_popOrZero(m_aNodeStack);
 
         OpSubSup();
-        SmNode *pSecond = m_aNodeStack.top();
-        m_aNodeStack.pop();
+        SmNode *pSecond = lcl_popOrZero(m_aNodeStack);
 
         Sum();
 
-        pSNode->SetSubNodes(pFirst, pSecond, m_aNodeStack.top());
-        m_aNodeStack.pop();
+        pSNode->SetSubNodes(pFirst, pSecond, lcl_popOrZero(m_aNodeStack));
         m_aNodeStack.push(pSNode);
     }
 }
@@ -1177,17 +1181,14 @@ void SmParser::Sum()
     while (TokenInGroup(TGSUM))
     {
         SmStructureNode *pSNode  = new SmBinHorNode(m_aCurToken);
-        SmNode *pFirst = m_aNodeStack.top();
-        m_aNodeStack.pop();
+        SmNode *pFirst = lcl_popOrZero(m_aNodeStack);
 
         OpSubSup();
-        SmNode *pSecond = m_aNodeStack.top();
-        m_aNodeStack.pop();
+        SmNode *pSecond = lcl_popOrZero(m_aNodeStack);
 
         Product();
 
-        pSNode->SetSubNodes(pFirst, pSecond, m_aNodeStack.top());
-        m_aNodeStack.pop();
+        pSNode->SetSubNodes(pFirst, pSecond, lcl_popOrZero(m_aNodeStack));
         m_aNodeStack.push(pSNode);
     }
 }
@@ -1199,9 +1200,8 @@ void SmParser::Product()
 
     while (TokenInGroup(TGPRODUCT))
     {   SmStructureNode *pSNode;
-        SmNode *pFirst = m_aNodeStack.top(),
+        SmNode *pFirst = lcl_popOrZero(m_aNodeStack),
                *pOper;
-        m_aNodeStack.pop();
         bool bSwitchArgs = false;
 
         SmTokenType eType = m_aCurToken.eType;
@@ -1223,8 +1223,7 @@ void SmParser::Product()
                 m_aCurToken.nGroup = TGPRODUCT;
 
                 GlyphSpecial();
-                pOper = m_aNodeStack.top();
-                m_aNodeStack.pop();
+                pOper = lcl_popOrZero(m_aNodeStack);
                 break;
 
             case TOVERBRACE :
@@ -1253,8 +1252,7 @@ void SmParser::Product()
                 pSNode = new SmBinHorNode(m_aCurToken);
 
                 OpSubSup();
-                pOper = m_aNodeStack.top();
-                m_aNodeStack.pop();
+                pOper = lcl_popOrZero(m_aNodeStack);
         }
 
         Power();
@@ -1262,13 +1260,11 @@ void SmParser::Product()
         if (bSwitchArgs)
         {
             //! vgl siehe SmBinDiagonalNode::Arrange
-            pSNode->SetSubNodes(pFirst, m_aNodeStack.top(), pOper);
-            m_aNodeStack.pop();
+            pSNode->SetSubNodes(pFirst, lcl_popOrZero(m_aNodeStack), pOper);
         }
         else
         {
-            pSNode->SetSubNodes(pFirst, pOper, m_aNodeStack.top());
-            m_aNodeStack.pop();
+            pSNode->SetSubNodes(pFirst, pOper, lcl_popOrZero(m_aNodeStack));
         }
         m_aNodeStack.push(pSNode);
     }
@@ -1295,8 +1291,7 @@ void SmParser::SubSup(sal_uLong nActiveGroup)
     // initialize subnodes array
     SmNodeArray  aSubNodes;
     aSubNodes.resize(1 + SUBSUP_NUM_ENTRIES);
-    aSubNodes[0] = m_aNodeStack.top();
-    m_aNodeStack.pop();
+    aSubNodes[0] = lcl_popOrZero(m_aNodeStack);
     for (sal_uInt16 i = 1;  i < aSubNodes.size();  i++)
         aSubNodes[i] = NULL;
 
@@ -1336,8 +1331,7 @@ void SmParser::SubSup(sal_uLong nActiveGroup)
         // set sub-/supscript if not already done
         if (aSubNodes[nIndex] != NULL)
             Error(PE_DOUBLE_SUBSUPSCRIPT);
-        aSubNodes[nIndex] = m_aNodeStack.top();
-        m_aNodeStack.pop();
+        aSubNodes[nIndex] = lcl_popOrZero(m_aNodeStack);
     }
 
     pNode->SetSubNodes(aSubNodes);
@@ -1544,18 +1538,18 @@ void SmParser::Term()
                     else
                         FontAttribut();
 
+                    SmNode* pTmp = lcl_popOrZero(m_aNodeStack);
+
                     // check if casting in following line is ok
-                    OSL_ENSURE(!m_aNodeStack.top()->IsVisible(), "Sm : Ooops...");
+                    OSL_ENSURE(pTmp && !pTmp->IsVisible(), "Sm : Ooops...");
 
-                    aArray[n] = (SmStructureNode *) m_aNodeStack.top();
-                    m_aNodeStack.pop();
+                    aArray[n] = (SmStructureNode *) pTmp;
                     n++;
                 }
 
                 Power();
 
-                SmNode *pFirstNode = m_aNodeStack.top();
-                m_aNodeStack.pop();
+                SmNode *pFirstNode = lcl_popOrZero(m_aNodeStack);
                 while (n > 0)
                 {   aArray[n - 1]->SetSubNodes(0, pFirstNode);
                     pFirstNode = aArray[n - 1];
@@ -1577,8 +1571,7 @@ void SmParser::Term()
                     //
                     Function();
 
-                    SmNode *pFunc = m_aNodeStack.top();
-                    m_aNodeStack.pop();
+                    SmNode *pFunc = lcl_popOrZero(m_aNodeStack);
 
                     if (m_aCurToken.eType == TLPARENT)
                     {   Term();
@@ -1591,8 +1584,7 @@ void SmParser::Term()
                     Insert('}', GetTokenIndex());
 
                     SmStructureNode *pSNode = new SmExpressionNode(pFunc->GetToken());
-                    pSNode->SetSubNodes(pFunc, m_aNodeStack.top());
-                    m_aNodeStack.pop();
+                    pSNode->SetSubNodes(pFunc, lcl_popOrZero(m_aNodeStack));
                     m_aNodeStack.push(pSNode);
                 }
             }
@@ -1650,14 +1642,12 @@ void SmParser::Operator()
 
         if (TokenInGroup(TGLIMIT) || TokenInGroup(TGPOWER))
             SubSup(m_aCurToken.nGroup);
-        SmNode *pOperator = m_aNodeStack.top();
-        m_aNodeStack.pop();
+        SmNode *pOperator = lcl_popOrZero(m_aNodeStack);
 
         // get argument
         Power();
 
-        pSNode->SetSubNodes(pOperator, m_aNodeStack.top());
-        m_aNodeStack.pop();
+        pSNode->SetSubNodes(pOperator, lcl_popOrZero(m_aNodeStack));
         m_aNodeStack.push(pSNode);
     }
 }
@@ -1745,8 +1735,7 @@ void SmParser::UnOper()
         case TNROOT :
             NextToken();
             Power();
-            pExtra = m_aNodeStack.top();
-            m_aNodeStack.pop();
+            pExtra = lcl_popOrZero(m_aNodeStack);
             break;
 
         case TUOPER :
@@ -1755,8 +1744,7 @@ void SmParser::UnOper()
             m_aCurToken.eType = TUOPER;
             m_aCurToken.nGroup = TGUNOPER;
             GlyphSpecial();
-            pOper = m_aNodeStack.top();
-            m_aNodeStack.pop();
+            pOper = lcl_popOrZero(m_aNodeStack);
             break;
 
         case TPLUS :
@@ -1766,8 +1754,7 @@ void SmParser::UnOper()
         case TNEG :
         case TFACT :
             OpSubSup();
-            pOper = m_aNodeStack.top();
-            m_aNodeStack.pop();
+            pOper = lcl_popOrZero(m_aNodeStack);
             break;
 
         default :
@@ -1776,8 +1763,7 @@ void SmParser::UnOper()
 
     // get argument
     Power();
-    pArg = m_aNodeStack.top();
-    m_aNodeStack.pop();
+    pArg = lcl_popOrZero(m_aNodeStack);
 
     if (eType == TABS)
     {   pSNode = new SmBraceNode(aNodeToken);
@@ -2041,8 +2027,7 @@ void SmParser::Brace()
 
             NextToken();
             Bracebody(true);
-            pBody = m_aNodeStack.top();
-            m_aNodeStack.pop();
+            pBody = lcl_popOrZero(m_aNodeStack);
 
             if (m_aCurToken.eType == TRIGHT)
             {   NextToken();
@@ -2070,8 +2055,7 @@ void SmParser::Brace()
 
             NextToken();
             Bracebody(false);
-            pBody = m_aNodeStack.top();
-            m_aNodeStack.pop();
+            pBody = lcl_popOrZero(m_aNodeStack);
 
             SmTokenType  eExpectedType = TUNKNOWN;
             switch (pLeft->GetToken().eType)
@@ -2168,8 +2152,7 @@ void SmParser::Bracebody(bool bIsLeftRight)
     aNodes.resize(nNum);
     for (sal_uInt16 i = 0;  i < nNum;  i++)
     {
-        aNodes[nNum - 1 - i] = m_aNodeStack.top();
-        m_aNodeStack.pop();
+        aNodes[nNum - 1 - i] = lcl_popOrZero(m_aNodeStack);
     }
 
     pBody->SetSubNodes(aNodes);
@@ -2229,8 +2212,7 @@ void SmParser::Binom()
 
     for (int i = 0;  i < 2;  i++)
     {
-        ExpressionArray[2 - (i + 1)] = m_aNodeStack.top();
-        m_aNodeStack.pop();
+        ExpressionArray[2 - (i + 1)] = lcl_popOrZero(m_aNodeStack);
     }
 
     pSNode->SetSubNodes(ExpressionArray);
@@ -2258,8 +2240,7 @@ void SmParser::Stack()
 
         for (sal_uInt16 i = 0; i < n; i++)
         {
-            ExpressionArray[n - (i + 1)] = m_aNodeStack.top();
-            m_aNodeStack.pop();
+            ExpressionArray[n - (i + 1)] = lcl_popOrZero(m_aNodeStack);
         }
 
         if (m_aCurToken.eType != TRGROUP)
@@ -2325,8 +2306,7 @@ void SmParser::Matrix()
 
         for (sal_uInt16 i = 0; i < (nRC); i++)
         {
-            ExpressionArray[(nRC) - (i + 1)] = m_aNodeStack.top();
-            m_aNodeStack.pop();
+            ExpressionArray[(nRC) - (i + 1)] = lcl_popOrZero(m_aNodeStack);
         }
 
         if (m_aCurToken.eType != TRGROUP)
@@ -2482,8 +2462,7 @@ SmNode *SmParser::Parse(const String &rBuffer)
     NextToken();
     Table();
 
-    SmNode* result = m_aNodeStack.top();
-    m_aNodeStack.pop();
+    SmNode* result = lcl_popOrZero(m_aNodeStack);
     return result;
 }
 
@@ -2508,8 +2487,7 @@ SmNode *SmParser::ParseExpression(const String &rBuffer)
     NextToken();
     Expression();
 
-    SmNode* result = m_aNodeStack.top();
-    m_aNodeStack.pop();
+    SmNode* result = lcl_popOrZero(m_aNodeStack);
     return result;
 }
 
diff --git a/vcl/source/gdi/cvtsvm.cxx b/vcl/source/gdi/cvtsvm.cxx
index bb5628f..7efd1f6 100644
--- a/vcl/source/gdi/cvtsvm.cxx
+++ b/vcl/source/gdi/cvtsvm.cxx
@@ -1155,8 +1155,14 @@ void SVMConverter::ImplConvertFromSVM1( SvStream& rIStm, GDIMetaFile& rMtf )
                 case( GDI_POP_ACTION ):
                 {
 
-                    LineInfo* pLineInfo = aLIStack.top();
-                    aLIStack.pop();
+                    LineInfo* pLineInfo;
+                    if (aLIStack.empty())
+                        pLineInfo = NULL;
+                    else
+                    {
+                        pLineInfo = aLIStack.top();
+                        aLIStack.pop();
+                    }
 
                     // restore line info
                     if( pLineInfo )
@@ -2068,8 +2074,14 @@ sal_uLong SVMConverter::ImplWriteActions( SvStream& rOStm, GDIMetaFile& rMtf,
 
             case( META_POP_ACTION ):
             {
-                Color* pCol = rLineColStack.top();
-                rLineColStack.pop();
+                Color* pCol;
+                if (rLineColStack.empty())
+                    pCol = NULL;
+                else
+                {
+                    pCol = rLineColStack.top();
+                    rLineColStack.pop();
+                }
 
                 if( pCol )
                 {


More information about the Libreoffice-commits mailing list