sw/source/core/crsr/crstrvl.cxx | 59 +++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 25 deletions(-)
New commits: commit 5979ab84e8a0038a1225020e19e4b884423247fc Author: Michael Stahl <[email protected]> Date: Thu Sep 11 10:34:51 2014 +0200 sw: actually check that iterator is valid Change-Id: Icefedf1d3fe09ed6670481dcdc4c5e745e816b1b diff --git a/sw/source/core/crsr/crstrvl.cxx b/sw/source/core/crsr/crstrvl.cxx index ab6c2d4..898f56b 100644 --- a/sw/source/core/crsr/crstrvl.cxx +++ b/sw/source/core/crsr/crstrvl.cxx @@ -635,7 +635,7 @@ lcl_FindField(bool & o_rFound, _SetGetExpFlds const& rSrtLst, _SetGetExpFlds::const_iterator it = rSrtLst.lower_bound(pSrch.get()); - o_rFound = (**it == *pSrch); + o_rFound = (it == rSrtLst.end()) ? false : (**it == *pSrch); return it; } commit cd994fc07f82bf950410bbdc88fbc4de7805547a Author: Michael Stahl <[email protected]> Date: Thu Sep 11 10:27:23 2014 +0200 sw: factor out a function to encapsulate object lifetimes Change-Id: Ie49cb4729d70f2b1fee9a2b7bd4ac095732a3d58 diff --git a/sw/source/core/crsr/crstrvl.cxx b/sw/source/core/crsr/crstrvl.cxx index 86ebf8c..ab6c2d4 100644 --- a/sw/source/core/crsr/crstrvl.cxx +++ b/sw/source/core/crsr/crstrvl.cxx @@ -608,6 +608,37 @@ void lcl_MakeFldLst( } } +static _SetGetExpFlds::const_iterator +lcl_FindField(bool & o_rFound, _SetGetExpFlds const& rSrtLst, + SwRootFrm *const pLayout, SwTxtNode *const pTxtNode, + SwTxtFld *const pTxtFld, SwPosition const& rPos, + sal_Int32 const nContentOffset) +{ + boost::scoped_ptr<_SetGetExpFld> pSrch; + boost::scoped_ptr<SwIndex> pIndex; + if (-1 == nContentOffset) + { + pSrch.reset(new _SetGetExpFld(rPos.nNode, pTxtFld, &rPos.nContent)); + } + else + { + pIndex.reset(new SwIndex(rPos.nNode.GetNode().GetCntntNode(), nContentOffset)); + pSrch.reset(new _SetGetExpFld(rPos.nNode, pTxtFld, pIndex.get())); + } + + if (rPos.nNode.GetIndex() < pTxtNode->GetNodes().GetEndOfExtras().GetIndex()) + { + // also at collection use only the first frame + Point aPt; + pSrch->SetBodyPos(*pTxtNode->getLayoutFrm(pLayout, &aPt, &rPos, false)); + } + + _SetGetExpFlds::const_iterator it = rSrtLst.lower_bound(pSrch.get()); + + o_rFound = (**it == *pSrch); + return it; +} + bool SwCrsrShell::MoveFldType( const SwFieldType* pFldType, const bool bNext, @@ -693,31 +724,9 @@ bool SwCrsrShell::MoveFldType( && rPos.nContent.GetIndex() != pTxtFld->GetStart()) nContentOffset = pTxtFld->GetStart(); } - - _SetGetExpFld *pSrch = NULL; - SwIndex *pIndex = NULL; - if( -1 == nContentOffset ) - { - pSrch = new _SetGetExpFld( rPos.nNode, pTxtFld, &rPos.nContent ); - } - else - { - pIndex = new SwIndex( rPos.nNode.GetNode().GetCntntNode(), nContentOffset ); - pSrch = new _SetGetExpFld( rPos.nNode, pTxtFld, pIndex ); - } - - if( rPos.nNode.GetIndex() < mpDoc->GetNodes().GetEndOfExtras().GetIndex() ) - { - // also at collection use only the first frame - Point aPt; - pSrch->SetBodyPos( *pTNd->getLayoutFrm( GetLayout(), &aPt, &rPos, false ) ); - } - - it = aSrtLst.lower_bound( pSrch ); - - bool isSrch = (**it == *pSrch); - delete pIndex; - delete pSrch; + bool isSrch; + it = lcl_FindField(isSrch, aSrtLst, + GetLayout(), pTNd, pTxtFld, rPos, nContentOffset); if( bDelFld ) { _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
