[PATCH libreoffice-4-0] sw: do not crash when it's not possible to insert fly

Michael Stahl (via Code Review) gerrit at gerrit.libreoffice.org
Fri Feb 15 13:50:35 PST 2013


Hi,

I have submitted a patch for review:

    https://gerrit.libreoffice.org/2176

To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/76/2176/1

sw: do not crash when it's not possible to insert fly

Change-Id: Idfcf54013107ba6b7ce3de0d0bddbef306698f33
(cherry picked from commit 5a80c24b145c8efe0dd384ef88e7d31173522fb8)
---
M sw/source/core/doc/doclay.cxx
1 file changed, 14 insertions(+), 3 deletions(-)



diff --git a/sw/source/core/doc/doclay.cxx b/sw/source/core/doc/doclay.cxx
index f31c998..3bac734 100644
--- a/sw/source/core/doc/doclay.cxx
+++ b/sw/source/core/doc/doclay.cxx
@@ -654,7 +654,11 @@
         if (pTxtNode != NULL)
         {
             SwFmtFlyCnt aFmt( pFmt );
-            pTxtNode->InsertItem( aFmt, nStt, nStt );
+            bool const bSuccess( pTxtNode->InsertItem(aFmt, nStt, nStt) );
+            if (!bSuccess) // may fail if there's no space left or header/ftr
+            {   // pFmt is dead now
+                return 0;
+            }
         }
     }
 
@@ -740,7 +744,9 @@
         if (bCalledFromShell && !lcl_IsItemSet(*pNewTxtNd, RES_PARATR_ADJUST) &&
             SFX_ITEM_SET == pAnchorNode->GetSwAttrSet().
             GetItemState(RES_PARATR_ADJUST, sal_True, &pItem))
+        {
             static_cast<SwCntntNode *>(pNewTxtNd)->SetAttr(*pItem);
+        }
 
          pFmt = _MakeFlySection( *pAnchorPos, *pNewTxtNd,
                                 eAnchorType, pFlySet, pFrmFmt );
@@ -941,8 +947,13 @@
     {
         xub_StrLen nStt = rRg.GetPoint()->nContent.GetIndex();
         SwFmtFlyCnt aFmt( pFmt );
-        rRg.GetPoint()->nNode.GetNode().GetTxtNode()->InsertItem(
-                aFmt, nStt, nStt );
+        bool const bSuccess( // may fail if there's no space left
+            rRg.GetPoint()->nNode.GetNode().GetTxtNode()->InsertItem(
+                    aFmt, nStt, nStt));
+        if (!bSuccess)
+        {   // pFmt is dead now
+            return 0;
+        }
     }
 
     SwDrawContact* pContact = new SwDrawContact( pFmt, &rDrawObj );

-- 
To view, visit https://gerrit.libreoffice.org/2176
To unsubscribe, visit https://gerrit.libreoffice.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Idfcf54013107ba6b7ce3de0d0bddbef306698f33
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: libreoffice-4-0
Gerrit-Owner: Michael Stahl <mstahl at redhat.com>


More information about the LibreOffice mailing list