[Libreoffice-commits] core.git: Branch 'libreoffice-5-3-3' - sw/source

Thorsten Behrens Thorsten.Behrens at CIB.de
Wed May 3 11:19:03 UTC 2017


 sw/source/core/undo/unattr.cxx |   22 +++++++++++-----------
 sw/source/core/undo/unfmco.cxx |    2 +-
 2 files changed, 12 insertions(+), 12 deletions(-)

New commits:
commit d866bb51927b8b75718438a63138834bb7ea2f6c
Author: Thorsten Behrens <Thorsten.Behrens at CIB.de>
Date:   Thu Apr 27 18:07:54 2017 +0200

    tdf#88555: band-aid fix, using GetPos/find instead of Contains
    
    to find out whether given format still exists.
    
    GetPos was replaced by Contains on multiple places in commit
    98436c4b53639d86f261ac630c46d32e3c7b8e28 but sometimes after
    series of undos/redos, vtable of some items in those format arrays
    becomes corrupt and it makes dynamic_cast (as used by Contains)
    fail and Writer falls flat on its face.
    
    This is just a workaround, no idea about the root cause.
    
    Change-Id: I1e02fd932dbac741687c15900841b9b7c778e2d4
    Reviewed-on: https://gerrit.libreoffice.org/37038
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
    (cherry picked from commit 1df637bde32c484b681ecdfebf56fdca03db7fc1)
    Reviewed-on: https://gerrit.libreoffice.org/37043
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    (cherry picked from commit e7068a7d9b945e0c6d4965445b6d951038e9c987)
    Reviewed-on: https://gerrit.libreoffice.org/37193
    Reviewed-by: Michael Stahl <mstahl at redhat.com>
    Reviewed-by: Katarina Behrens <Katarina.Behrens at cib.de>
    Tested-by: Katarina Behrens <Katarina.Behrens at cib.de>

diff --git a/sw/source/core/undo/unattr.cxx b/sw/source/core/undo/unattr.cxx
index 4641aa08cd39..58087e2c0aa0 100644
--- a/sw/source/core/undo/unattr.cxx
+++ b/sw/source/core/undo/unattr.cxx
@@ -200,21 +200,21 @@ bool SwUndoFormatAttr::IsFormatInDoc( SwDoc* pDoc )
 {
     // search for the Format in the Document; if it does not exist any more,
     // the attribute is not restored!
-    bool bFound = false;
+    size_t nPos = SIZE_MAX;
     switch ( m_nFormatWhich )
     {
         case RES_TXTFMTCOLL:
         case RES_CONDTXTFMTCOLL:
-            bFound = pDoc->GetTextFormatColls()->Contains( m_pFormat );
+            nPos = pDoc->GetTextFormatColls()->GetPos( m_pFormat );
             break;
 
         case RES_GRFFMTCOLL:
-            bFound = pDoc->GetGrfFormatColls()->Contains(
+            nPos = pDoc->GetGrfFormatColls()->GetPos(
                     static_cast<const SwGrfFormatColl*>(m_pFormat) );
             break;
 
         case RES_CHRFMT:
-            bFound = pDoc->GetCharFormats()->Contains( m_pFormat );
+            nPos = pDoc->GetCharFormats()->GetPos( m_pFormat );
             break;
 
         case RES_FRMFMT:
@@ -225,14 +225,14 @@ bool SwUndoFormatAttr::IsFormatInDoc( SwDoc* pDoc )
                 {
                     m_pFormat =
                         static_cast<SwTableNode*>(pNd)->GetTable().GetFrameFormat();
-                    bFound = true;
+                    nPos = 0;
                     break;
                 }
                 else if ( pNd->IsSectionNode() )
                 {
                     m_pFormat =
                         static_cast<SwSectionNode*>(pNd)->GetSection().GetFormat();
-                    bFound = true;
+                    nPos = 0;
                     break;
                 }
                 else if ( pNd->IsStartNode() && (SwTableBoxStartNode ==
@@ -246,7 +246,7 @@ bool SwUndoFormatAttr::IsFormatInDoc( SwDoc* pDoc )
                         if ( pBox )
                         {
                             m_pFormat = pBox->GetFrameFormat();
-                            bFound = true;
+                            nPos = 0;
                             break;
                         }
                     }
@@ -255,13 +255,13 @@ bool SwUndoFormatAttr::IsFormatInDoc( SwDoc* pDoc )
             SAL_FALLTHROUGH;
         case RES_DRAWFRMFMT:
         case RES_FLYFRMFMT:
-            if (pDoc->GetSpzFrameFormats()->Contains( m_pFormat )
-                    || pDoc->GetFrameFormats()->Contains( m_pFormat ))
-                bFound = true;
+            if ( ( pDoc->GetSpzFrameFormats()->find( static_cast<SwFrameFormat*>(m_pFormat) ) != pDoc->GetSpzFrameFormats()->end() )
+                || ( pDoc->GetFrameFormats()->find( static_cast<SwFrameFormat*>( m_pFormat ) ) != pDoc->GetFrameFormats()->end() ) )
+                nPos = 0;
             break;
     }
 
-    if ( !bFound )
+    if ( nPos == SIZE_MAX )
     {
         // Format does not exist; reset
         m_pFormat = nullptr;
diff --git a/sw/source/core/undo/unfmco.cxx b/sw/source/core/undo/unfmco.cxx
index 5aeaf87e70d5..c473f630ab92 100644
--- a/sw/source/core/undo/unfmco.cxx
+++ b/sw/source/core/undo/unfmco.cxx
@@ -74,7 +74,7 @@ void SwUndoFormatColl::DoSetFormatColl(SwDoc & rDoc, SwPaM & rPaM)
     // this array.
 
     // does the format still exist?
-    if( rDoc.GetTextFormatColls()->Contains(static_cast<SwTextFormatColl*>(pFormatColl)) )
+    if( SIZE_MAX != rDoc.GetTextFormatColls()->GetPos(static_cast<SwTextFormatColl*>(pFormatColl)) )
     {
         rDoc.SetTextFormatColl(rPaM, static_cast<SwTextFormatColl*>(pFormatColl), mbReset,
                            mbResetListAttrs);


More information about the Libreoffice-commits mailing list