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

Michael Stahl mstahl at redhat.com
Wed Mar 7 08:05:26 UTC 2018


 sw/source/core/layout/sectfrm.cxx |   70 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 70 insertions(+)

New commits:
commit 1615d0eb285eeaf3da10b4ed727b776b0a28b94d
Author: Michael Stahl <mstahl at redhat.com>
Date:   Tue Mar 6 10:04:28 2018 +0100

    sw: add some sanity check to SwFrame::GetNextSctLeaf()
    
    Check that the parents of the section follow frame are the same type as
    the parents of the original section frame.
    
    Change-Id: I9845e48834d57b8a93f9b850cb89b6c5544d9ab2
    Reviewed-on: https://gerrit.libreoffice.org/50807
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>

diff --git a/sw/source/core/layout/sectfrm.cxx b/sw/source/core/layout/sectfrm.cxx
index 786cca7ffbae..502650c34e53 100644
--- a/sw/source/core/layout/sectfrm.cxx
+++ b/sw/source/core/layout/sectfrm.cxx
@@ -1592,6 +1592,14 @@ SwLayoutFrame *SwFrame::GetNextSctLeaf( MakePageType eMakePage )
         }
     }
 
+#ifndef NDEBUG
+    std::vector<SwFrame *> parents;
+    for (SwFrame * pTmp = GetUpper(); !pTmp->IsPageFrame(); pTmp = pTmp->GetUpper())
+    {
+        parents.push_back(pTmp);
+    }
+#endif
+
     // Always end up in the same section: Body again inside Body etc.
     const bool bBody = IsInDocBody();
     const bool bFootnotePage = FindPageFrame()->IsFootnotePage();
@@ -1730,6 +1738,68 @@ SwLayoutFrame *SwFrame::GetNextSctLeaf( MakePageType eMakePage )
             SwRectFnSet aRectFnSet(pNew);
             aRectFnSet.MakePos( *pNew, pLayLeaf, nullptr, true );
 
+#ifndef NDEBUG
+            {   // sanity check the parents of the new frame vs. the old frame
+                SwFrame * pTmp = pNew;
+                auto iter(parents.begin());
+                if (parents.size() >= 2 &&
+                    parents[0]->IsBodyFrame() && parents[1]->IsColumnFrame())
+                {   // this only inserts section frame - remove column
+                    assert(parents[2]->IsSctFrame());
+                    std::advance(iter, +2);
+                }
+                else  if (IsSctFrame()) // special case: "this" is the section
+                {
+                    pTmp = pTmp->GetUpper();
+                }
+
+                for ( ; iter != parents.end(); ++iter)
+                {
+                    assert(!pTmp->IsPageFrame());
+                    assert(pTmp->GetType() == (*iter)->GetType());
+                    // for cell frames and table frames:
+                    // 1) there may be multliple follow frames of the old one
+                    // 2) the new frame may be identical to the old one
+                    //    (not sure if this is allowed, but it happens now
+                    //     for the outer table of a nested table)
+                    if (pTmp->IsCellFrame())
+                    {
+                        SwCellFrame const*const pNewF(static_cast<SwCellFrame*>(pTmp));
+                        SwCellFrame const*const pOldF(static_cast<SwCellFrame*>(*iter));
+                        bool bFollowFound(false);
+                        for (SwCellFrame const* pOldIter = pOldF;
+                            pOldIter; pOldIter = pOldIter->GetFollowCell())
+                        {
+                            if (pOldIter == pNewF)
+                            {
+                                bFollowFound = true;
+                                break;
+                            }
+                        }
+                        assert(bFollowFound);
+                    }
+                    else if (pTmp->IsFlowFrame())
+                    {
+                        SwFlowFrame const*const pNewF(SwFlowFrame::CastFlowFrame(pTmp));
+                        SwFlowFrame const*const pOldF(SwFlowFrame::CastFlowFrame(*iter));
+                        bool bFollowFound(false);
+                        for (SwFlowFrame const* pOldIter = pOldF;
+                            pOldIter; pOldIter = pOldIter->GetFollow())
+                        {
+                            if (pOldIter == pNewF)
+                            {
+                                bFollowFound = true;
+                                break;
+                            }
+                        }
+                        assert(bFollowFound);
+                    }
+                    pTmp = pTmp->GetUpper();
+                }
+                assert(pTmp->IsPageFrame());
+            }
+#endif
+
             // If our section frame has a successor then that has to be
             // moved behind the new Follow of the section frames
             SwFrame* pTmp = pSect->GetNext();


More information about the Libreoffice-commits mailing list