diff options
author | Michael Stahl <mstahl@redhat.com> | 2018-03-06 10:04:28 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2018-03-07 09:05:02 +0100 |
commit | 1615d0eb285eeaf3da10b4ed727b776b0a28b94d (patch) | |
tree | ea9153e4ff12195aad29f29e51e7930717b8683e /sw | |
parent | 856c57f20f9b07c686a854e0ccbb6ee3b0ee4791 (diff) |
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@libreoffice.org>
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/source/core/layout/sectfrm.cxx | 70 |
1 files changed, 70 insertions, 0 deletions
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(); |