Kaydet (Commit) 1615d0eb authored tarafından Michael Stahl's avatar Michael Stahl Kaydeden (comit) Miklos Vajna

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/50807Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
üst 856c57f2
......@@ -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();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment