[Libreoffice-commits] core.git: writerfilter/source

Caolán McNamara caolanm at redhat.com
Wed Nov 19 04:12:51 PST 2014


 writerfilter/source/rtftok/rtfdocumentimpl.cxx |  156 +++++++++++++------------
 1 file changed, 85 insertions(+), 71 deletions(-)

New commits:
commit 185dae1969bb463ae1be8ea46a7780efa32372f5
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Wed Nov 19 12:11:47 2014 +0000

    Resolves: fdo#86451 guard all the tops post pop
    
    Change-Id: Ic89edb94c6c12a66fd46e0630115a458857cc6cc

diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index a48553c..1234e37 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -5790,7 +5790,7 @@ int RTFDocumentImpl::popState()
     case DESTINATION_PARAGRAPHNUMBERING:
     {
         RTFValue::Pointer_t pIdValue = aState.aTableAttributes.find(NS_ooxml::LN_CT_AbstractNum_nsid);
-        if (pIdValue.get())
+        if (pIdValue.get() && !m_aStates.empty())
         {
             // Abstract numbering
             RTFSprms aLeveltextAttributes;
@@ -5859,87 +5859,98 @@ int RTFDocumentImpl::popState()
     }
     break;
     case DESTINATION_PARAGRAPHNUMBERING_TEXTAFTER:
-    {
-        // FIXME: don't use pDestinationText, points to popped state
-        RTFValue::Pointer_t pValue(new RTFValue(aState.aDestinationText.makeStringAndClear(), true));
-        m_aStates.top().aTableAttributes.set(NS_ooxml::LN_CT_LevelSuffix_val, pValue);
-    }
+        if (!m_aStates.empty())
+        {
+            // FIXME: don't use pDestinationText, points to popped state
+            RTFValue::Pointer_t pValue(new RTFValue(aState.aDestinationText.makeStringAndClear(), true));
+            m_aStates.top().aTableAttributes.set(NS_ooxml::LN_CT_LevelSuffix_val, pValue);
+        }
     break;
     case DESTINATION_PARAGRAPHNUMBERING_TEXTBEFORE:
-    {
-        // FIXME: don't use pDestinationText, points to popped state
-        RTFValue::Pointer_t pValue(new RTFValue(aState.aDestinationText.makeStringAndClear(), true));
-        m_aStates.top().aTableAttributes.set(NS_ooxml::LN_CT_LevelText_val, pValue);
-    }
+        if (!m_aStates.empty())
+        {
+            // FIXME: don't use pDestinationText, points to popped state
+            RTFValue::Pointer_t pValue(new RTFValue(aState.aDestinationText.makeStringAndClear(), true));
+            m_aStates.top().aTableAttributes.set(NS_ooxml::LN_CT_LevelText_val, pValue);
+        }
     break;
     case DESTINATION_LISTNAME:
         break;
     case DESTINATION_LISTLEVEL:
-    {
-        RTFValue::Pointer_t pInnerValue(new RTFValue(m_aStates.top().nListLevelNum++));
-        aState.aTableAttributes.set(NS_ooxml::LN_CT_Lvl_ilvl, pInnerValue);
+        if (!m_aStates.empty())
+        {
+            RTFValue::Pointer_t pInnerValue(new RTFValue(m_aStates.top().nListLevelNum++));
+            aState.aTableAttributes.set(NS_ooxml::LN_CT_Lvl_ilvl, pInnerValue);
 
-        RTFValue::Pointer_t pValue(new RTFValue(aState.aTableAttributes, aState.aTableSprms));
-        if (m_aStates.top().nDestinationState != DESTINATION_LFOLEVEL)
-            m_aStates.top().aListLevelEntries.set(NS_ooxml::LN_CT_AbstractNum_lvl, pValue, OVERWRITE_NO_APPEND);
-        else
-            m_aStates.top().aTableSprms.set(NS_ooxml::LN_CT_NumLvl_lvl, pValue);
-    }
+            RTFValue::Pointer_t pValue(new RTFValue(aState.aTableAttributes, aState.aTableSprms));
+            if (m_aStates.top().nDestinationState != DESTINATION_LFOLEVEL)
+                m_aStates.top().aListLevelEntries.set(NS_ooxml::LN_CT_AbstractNum_lvl, pValue, OVERWRITE_NO_APPEND);
+            else
+                m_aStates.top().aTableSprms.set(NS_ooxml::LN_CT_NumLvl_lvl, pValue);
+        }
     break;
     case DESTINATION_LFOLEVEL:
-    {
-        RTFValue::Pointer_t pInnerValue(new RTFValue(m_aStates.top().nListLevelNum++));
-        aState.aTableAttributes.set(NS_ooxml::LN_CT_NumLvl_ilvl, pInnerValue);
+        if (!m_aStates.empty())
+        {
+            RTFValue::Pointer_t pInnerValue(new RTFValue(m_aStates.top().nListLevelNum++));
+            aState.aTableAttributes.set(NS_ooxml::LN_CT_NumLvl_ilvl, pInnerValue);
 
-        RTFValue::Pointer_t pValue(new RTFValue(aState.aTableAttributes, aState.aTableSprms));
-        m_aStates.top().aTableSprms.set(NS_ooxml::LN_CT_Num_lvlOverride, pValue);
-    }
+            RTFValue::Pointer_t pValue(new RTFValue(aState.aTableAttributes, aState.aTableSprms));
+            m_aStates.top().aTableSprms.set(NS_ooxml::LN_CT_Num_lvlOverride, pValue);
+        }
     break;
     // list override table
     case DESTINATION_LISTOVERRIDEENTRY:
-    {
-        if (m_aStates.top().nDestinationState == DESTINATION_LISTOVERRIDEENTRY)
-        {
-            // copy properties upwards so upper popState inserts it
-            m_aStates.top().aTableAttributes = aState.aTableAttributes;
-            m_aStates.top().aTableSprms = aState.aTableSprms;
-        }
-        else
+        if (!m_aStates.empty())
         {
-            RTFValue::Pointer_t pValue(new RTFValue(
-                                           aState.aTableAttributes, aState.aTableSprms));
-            m_aListTableSprms.set(NS_ooxml::LN_CT_Numbering_num, pValue, OVERWRITE_NO_APPEND);
+            if (m_aStates.top().nDestinationState == DESTINATION_LISTOVERRIDEENTRY)
+            {
+                // copy properties upwards so upper popState inserts it
+                m_aStates.top().aTableAttributes = aState.aTableAttributes;
+                m_aStates.top().aTableSprms = aState.aTableSprms;
+            }
+            else
+            {
+                RTFValue::Pointer_t pValue(new RTFValue(
+                                               aState.aTableAttributes, aState.aTableSprms));
+                m_aListTableSprms.set(NS_ooxml::LN_CT_Numbering_num, pValue, OVERWRITE_NO_APPEND);
+            }
         }
-    }
     break;
     case DESTINATION_LEVELTEXT:
-    {
-        RTFValue::Pointer_t pValue(new RTFValue(aState.aTableAttributes));
-        m_aStates.top().aTableSprms.set(NS_ooxml::LN_CT_Lvl_lvlText, pValue);
-    }
+        if (!m_aStates.empty())
+        {
+            RTFValue::Pointer_t pValue(new RTFValue(aState.aTableAttributes));
+            m_aStates.top().aTableSprms.set(NS_ooxml::LN_CT_Lvl_lvlText, pValue);
+        }
     break;
     case DESTINATION_LEVELNUMBERS:
-        m_aStates.top().aTableSprms = aState.aTableSprms;
+        if (!m_aStates.empty())
+            m_aStates.top().aTableSprms = aState.aTableSprms;
         break;
     case DESTINATION_FIELDINSTRUCTION:
-        m_aStates.top().nFieldStatus = FIELD_INSTRUCTION;
+        if (!m_aStates.empty())
+            m_aStates.top().nFieldStatus = FIELD_INSTRUCTION;
         break;
     case DESTINATION_FIELDRESULT:
-        m_aStates.top().nFieldStatus = FIELD_RESULT;
+        if (!m_aStates.empty())
+            m_aStates.top().nFieldStatus = FIELD_RESULT;
         break;
     case DESTINATION_FIELD:
         if (aState.nFieldStatus == FIELD_INSTRUCTION)
             singleChar(0x15);
         break;
     case DESTINATION_SHAPEPROPERTYVALUEPICT:
-    {
-        m_aStates.top().aPicture = aState.aPicture;
-        // both \sp and \sv are destinations, copy the text up-ward for later
-        m_aStates.top().aDestinationText = aState.aDestinationText;
-    }
+        if (!m_aStates.empty())
+        {
+            m_aStates.top().aPicture = aState.aPicture;
+            // both \sp and \sv are destinations, copy the text up-ward for later
+            m_aStates.top().aDestinationText = aState.aDestinationText;
+        }
     break;
     case DESTINATION_FALT:
-        m_aStates.top().aTableSprms = aState.aTableSprms;
+        if (!m_aStates.empty())
+            m_aStates.top().aTableSprms = aState.aTableSprms;
         break;
     case DESTINATION_SHAPEPROPERTYNAME:
     case DESTINATION_SHAPEPROPERTYVALUE:
@@ -5970,27 +5981,30 @@ int RTFDocumentImpl::popState()
         }
         break;
     case DESTINATION_SHAPETEXT:
-        // If we're leaving the shapetext group (it may have nested ones) and this is a shape, not an old drawingobject.
-        if (m_aStates.top().nDestinationState != DESTINATION_SHAPETEXT && !m_aStates.top().aDrawingObject.bHadShapeText)
+        if (!m_aStates.empty())
         {
-            m_aStates.top().bHadShapeText = true;
-            if (!m_aStates.top().pCurrentBuffer)
-                m_pSdrImport->close();
-            else
-                m_aStates.top().pCurrentBuffer->push_back(
-                    Buf_t(BUFFER_ENDSHAPE));
-        }
-
-        // It's allowed to declare these inside the shape text, and they
-        // are expected to have an effect for the whole shape.
-        if (aState.aDrawingObject.nLeft)
-            m_aStates.top().aDrawingObject.nLeft = aState.aDrawingObject.nLeft;
-        if (aState.aDrawingObject.nTop)
-            m_aStates.top().aDrawingObject.nTop = aState.aDrawingObject.nTop;
-        if (aState.aDrawingObject.nRight)
-            m_aStates.top().aDrawingObject.nRight = aState.aDrawingObject.nRight;
-        if (aState.aDrawingObject.nBottom)
-            m_aStates.top().aDrawingObject.nBottom = aState.aDrawingObject.nBottom;
+            // If we're leaving the shapetext group (it may have nested ones) and this is a shape, not an old drawingobject.
+            if (m_aStates.top().nDestinationState != DESTINATION_SHAPETEXT && !m_aStates.top().aDrawingObject.bHadShapeText)
+            {
+                m_aStates.top().bHadShapeText = true;
+                if (!m_aStates.top().pCurrentBuffer)
+                    m_pSdrImport->close();
+                else
+                    m_aStates.top().pCurrentBuffer->push_back(
+                        Buf_t(BUFFER_ENDSHAPE));
+            }
+
+            // It's allowed to declare these inside the shape text, and they
+            // are expected to have an effect for the whole shape.
+            if (aState.aDrawingObject.nLeft)
+                m_aStates.top().aDrawingObject.nLeft = aState.aDrawingObject.nLeft;
+            if (aState.aDrawingObject.nTop)
+                m_aStates.top().aDrawingObject.nTop = aState.aDrawingObject.nTop;
+            if (aState.aDrawingObject.nRight)
+                m_aStates.top().aDrawingObject.nRight = aState.aDrawingObject.nRight;
+            if (aState.aDrawingObject.nBottom)
+                m_aStates.top().aDrawingObject.nBottom = aState.aDrawingObject.nBottom;
+        }
         break;
     default:
     {


More information about the Libreoffice-commits mailing list