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

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Sun Apr 19 13:19:23 UTC 2020


 sw/source/core/doc/docfly.cxx     |   30 ++++++++++----------
 sw/source/core/doc/docfmt.cxx     |   47 +++++++++++++++++--------------
 sw/source/core/doc/docftn.cxx     |   26 ++++++++++-------
 sw/source/core/doc/docglbl.cxx    |   14 +++++----
 sw/source/core/doc/doclay.cxx     |   23 ++++++++-------
 sw/source/core/doc/docnum.cxx     |   19 ++++++------
 sw/source/core/doc/docredln.cxx   |   33 ++++++++++++----------
 sw/source/core/doc/docruby.cxx    |   12 +++++---
 sw/source/core/doc/docsort.cxx    |   16 +++++++---
 sw/source/core/doc/doctxm.cxx     |   26 +++++++++++------
 sw/source/core/doc/ftnidx.cxx     |   12 ++++----
 sw/source/core/doc/gctable.cxx    |   51 ++++++++++++++++++----------------
 sw/source/core/doc/number.cxx     |   16 ++++++----
 sw/source/core/doc/tblrwcl.cxx    |   57 ++++++++++++++++++++++++--------------
 sw/source/core/docnode/ndsect.cxx |   15 ++++++----
 sw/source/core/inc/swcache.hxx    |   16 ++++++++--
 16 files changed, 244 insertions(+), 169 deletions(-)

New commits:
commit 32857aa4d1f6ca67f33068cd4caaf62bb5a75f5c
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Sun Apr 19 13:12:25 2020 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Sun Apr 19 15:18:43 2020 +0200

    loplugin:buriedassign in sw(2)
    
    Change-Id: If73cbea9eb11029ef6b48a36e20d2271966ac4d1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92496
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sw/source/core/doc/docfly.cxx b/sw/source/core/doc/docfly.cxx
index 99c9b580bd8e..7328fe0b763e 100644
--- a/sw/source/core/doc/docfly.cxx
+++ b/sw/source/core/doc/docfly.cxx
@@ -79,10 +79,10 @@ size_t SwDoc::GetFlyCount( FlyCntType eType, bool bIgnoreTextBoxes ) const
         if (bIgnoreTextBoxes && SwTextBoxHelper::isTextBox(pFlyFormat, RES_FLYFRMFMT))
             continue;
 
-        if( RES_FLYFRMFMT == pFlyFormat->Which()
-            && nullptr != ( pIdx = pFlyFormat->GetContent().GetContentIdx() )
-            && pIdx->GetNodes().IsDocNodes()
-            )
+        if( RES_FLYFRMFMT != pFlyFormat->Which() )
+            continue;
+        pIdx = pFlyFormat->GetContent().GetContentIdx();
+        if( pIdx && pIdx->GetNodes().IsDocNodes() )
         {
             const SwNode* pNd = GetNodes()[ pIdx->GetIndex() + 1 ];
 
@@ -127,10 +127,10 @@ SwFrameFormat* SwDoc::GetFlyNum( size_t nIdx, FlyCntType eType, bool bIgnoreText
         if (bIgnoreTextBoxes && SwTextBoxHelper::isTextBox(pFlyFormat, RES_FLYFRMFMT))
             continue;
 
-        if( RES_FLYFRMFMT == pFlyFormat->Which()
-            && nullptr != ( pIdx = pFlyFormat->GetContent().GetContentIdx() )
-            && pIdx->GetNodes().IsDocNodes()
-            )
+        if( RES_FLYFRMFMT != pFlyFormat->Which() )
+            continue;
+        pIdx = pFlyFormat->GetContent().GetContentIdx();
+        if( pIdx && pIdx->GetNodes().IsDocNodes() )
         {
             const SwNode* pNd = GetNodes()[ pIdx->GetIndex() + 1 ];
             switch( eType )
@@ -1014,14 +1014,14 @@ SwChainRet SwDoc::Chainable( const SwFrameFormat &rSource, const SwFrameFormat &
     for( auto pSpzFrameFm : *GetSpzFrameFormats() )
     {
         const SwFormatAnchor& rAnchor = pSpzFrameFm->GetAnchor();
-        sal_uLong nTstSttNd;
         // #i20622# - to-frame anchored objects are allowed.
-        if ( ((rAnchor.GetAnchorId() == RndStdIds::FLY_AT_PARA) ||
-              (rAnchor.GetAnchorId() == RndStdIds::FLY_AT_CHAR)) &&
-             nullptr != rAnchor.GetContentAnchor() &&
-             nFlySttNd <= ( nTstSttNd =
-                         rAnchor.GetContentAnchor()->nNode.GetIndex() ) &&
-             nTstSttNd < nFlySttNd + 2 )
+        if ( (rAnchor.GetAnchorId() != RndStdIds::FLY_AT_PARA) &&
+             (rAnchor.GetAnchorId() != RndStdIds::FLY_AT_CHAR) )
+            continue;
+        if ( nullptr == rAnchor.GetContentAnchor() )
+            continue;
+        sal_uLong nTstSttNd = rAnchor.GetContentAnchor()->nNode.GetIndex();
+        if( nFlySttNd <= nTstSttNd && nTstSttNd < nFlySttNd + 2 )
         {
             return SwChainRet::NOT_EMPTY;
         }
diff --git a/sw/source/core/doc/docfmt.cxx b/sw/source/core/doc/docfmt.cxx
index 1768221fb922..f0a3e2a5fb35 100644
--- a/sw/source/core/doc/docfmt.cxx
+++ b/sw/source/core/doc/docfmt.cxx
@@ -579,15 +579,16 @@ void SwDoc::SetDefault( const SfxItemSet& rSet )
         // also copy the defaults
         if( bCheckSdrDflt )
         {
-            sal_uInt16 nEdtWhich, nSlotId;
-            if( 0 != (nSlotId = GetAttrPool().GetSlotId( nWhich ) ) &&
-                nSlotId != nWhich &&
-                0 != (nEdtWhich = pSdrPool->GetWhich( nSlotId )) &&
-                nSlotId != nEdtWhich )
+            sal_uInt16 nSlotId = GetAttrPool().GetSlotId( nWhich );
+            if( 0 != nSlotId && nSlotId != nWhich )
             {
-                std::unique_ptr<SfxPoolItem> pCpy(pItem->Clone());
-                pCpy->SetWhich( nEdtWhich );
-                pSdrPool->SetPoolDefaultItem( *pCpy );
+                sal_uInt16 nEdtWhich = pSdrPool->GetWhich( nSlotId );
+                if( 0 != nEdtWhich && nSlotId != nEdtWhich )
+                {
+                    std::unique_ptr<SfxPoolItem> pCpy(pItem->Clone());
+                    pCpy->SetWhich( nEdtWhich );
+                    pSdrPool->SetPoolDefaultItem( *pCpy );
+                }
             }
         }
 
@@ -1209,17 +1210,18 @@ SwTextFormatColl* SwDoc::CopyTextColl( const SwTextFormatColl& rColl )
         if( SfxItemState::SET == pNewColl->GetItemState( RES_PARATR_NUMRULE,
             false, &pItem ))
         {
-            const SwNumRule* pRule;
             const OUString& rName = static_cast<const SwNumRuleItem*>(pItem)->GetValue();
-            if( !rName.isEmpty() &&
-                nullptr != ( pRule = rColl.GetDoc()->FindNumRulePtr( rName )) &&
-                !pRule->IsAutoRule() )
+            if( !rName.isEmpty() )
             {
-                SwNumRule* pDestRule = FindNumRulePtr( rName );
-                if( pDestRule )
-                    pDestRule->SetInvalidRule( true );
-                else
-                    MakeNumRule( rName, pRule );
+                const SwNumRule* pRule = rColl.GetDoc()->FindNumRulePtr( rName );
+                if( pRule && !pRule->IsAutoRule() )
+                {
+                    SwNumRule* pDestRule = FindNumRulePtr( rName );
+                    if( pDestRule )
+                        pDestRule->SetInvalidRule( true );
+                    else
+                        MakeNumRule( rName, pRule );
+                }
             }
         }
     }
@@ -1731,11 +1733,14 @@ SwTableNumFormatMerge::SwTableNumFormatMerge( const SwDoc& rSrc, SwDoc& rDest )
     : pNFormat( nullptr )
 {
     // a different Doc -> Number formatter needs to be merged
-    SvNumberFormatter* pN;
-    if( &rSrc != &rDest && nullptr != ( pN = const_cast<SwDoc&>(rSrc).GetNumberFormatter( false ) ))
+    if( &rSrc != &rDest )
     {
-        pNFormat = rDest.GetNumberFormatter();
-        pNFormat->MergeFormatter( *pN );
+        SvNumberFormatter* pN = const_cast<SwDoc&>(rSrc).GetNumberFormatter( false );
+        if( pN )
+        {
+            pNFormat = rDest.GetNumberFormatter();
+            pNFormat->MergeFormatter( *pN );
+        }
     }
 
     if( &rSrc != &rDest )
diff --git a/sw/source/core/doc/docftn.cxx b/sw/source/core/doc/docftn.cxx
index 36178ab18090..90899b91a002 100644
--- a/sw/source/core/doc/docftn.cxx
+++ b/sw/source/core/doc/docftn.cxx
@@ -451,15 +451,16 @@ bool SwDoc::SetCurFootnote( const SwPaM& rPam, const OUString& rNumStr,
         pUndo.reset(new SwUndoChangeFootNote( rPam, rNumStr, bIsEndNote ));
     }
 
-    SwTextFootnote* pTextFootnote = nullptr;
-    sal_uLong nIdx;
     bool bChg = false;
     bool bTypeChgd = false;
     const size_t nPosSave = nPos;
-    while( nPos < rFootnoteArr.size() &&
-            (( nIdx = SwTextFootnote_GetIndex((pTextFootnote = rFootnoteArr[ nPos++ ] )))
-                < nEndNd || ( nIdx == nEndNd &&
-                nEndCnt >= pTextFootnote->GetStart() )) )
+    while( nPos < rFootnoteArr.size() )
+    {
+        SwTextFootnote* pTextFootnote = rFootnoteArr[ nPos++ ];
+        sal_uLong nIdx = SwTextFootnote_GetIndex(pTextFootnote);
+        if( nIdx >= nEndNd &&
+            ( nIdx != nEndNd || nEndCnt < pTextFootnote->GetStart() ) )
+            continue;
         if( nIdx > nSttNd || ( nIdx == nSttNd &&
                 nSttCnt <= pTextFootnote->GetStart() ) )
         {
@@ -484,12 +485,16 @@ bool SwDoc::SetCurFootnote( const SwPaM& rPam, const OUString& rNumStr,
                 }
             }
         }
+    }
 
     nPos = nPosSave;       // There are more in the front!
-    while( nPos &&
-            (( nIdx = SwTextFootnote_GetIndex((pTextFootnote = rFootnoteArr[ --nPos ] )))
-                > nSttNd || ( nIdx == nSttNd &&
-                nSttCnt <= pTextFootnote->GetStart() )) )
+    while( nPos )
+    {
+        SwTextFootnote* pTextFootnote = rFootnoteArr[ --nPos ];
+        sal_uLong nIdx = SwTextFootnote_GetIndex(pTextFootnote);
+        if( nIdx <= nSttNd &&
+            ( nIdx != nSttNd || nSttCnt > pTextFootnote->GetStart() ) )
+            continue;
         if( nIdx < nEndNd || ( nIdx == nEndNd &&
             nEndCnt >= pTextFootnote->GetStart() ) )
         {
@@ -512,6 +517,7 @@ bool SwDoc::SetCurFootnote( const SwPaM& rPam, const OUString& rNumStr,
                 }
             }
         }
+    }
 
     // Who needs to be triggered?
     if( bChg )
diff --git a/sw/source/core/doc/docglbl.cxx b/sw/source/core/doc/docglbl.cxx
index c1d2c0c8b26a..4cc2afb20db1 100644
--- a/sw/source/core/doc/docglbl.cxx
+++ b/sw/source/core/doc/docglbl.cxx
@@ -87,13 +87,14 @@ bool SwDoc::GenerateHTMLDoc( const OUString& rPath,
 // two helpers for outline mode
 static SwNodePtr GetStartNode( SwOutlineNodes const * pOutlNds, int nOutlineLevel, SwOutlineNodes::size_type* nOutl )
 {
-    SwNodePtr pNd;
-
     for( ; *nOutl < pOutlNds->size(); ++(*nOutl) )
-        if( ( pNd = (*pOutlNds)[ *nOutl ])->GetTextNode()->GetAttrOutlineLevel() == nOutlineLevel && !pNd->FindTableNode() )
+    {
+        SwNodePtr pNd = (*pOutlNds)[ *nOutl ];
+        if( pNd->GetTextNode()->GetAttrOutlineLevel() == nOutlineLevel && !pNd->FindTableNode() )
         {
             return pNd;
         }
+    }
 
     return nullptr;
 }
@@ -120,14 +121,15 @@ static SwNodePtr GetEndNode( SwOutlineNodes const * pOutlNds, int nOutlineLevel,
 // two helpers for collection mode
 static SwNodePtr GetStartNode( const SwOutlineNodes* pOutlNds, const SwTextFormatColl* pSplitColl, SwOutlineNodes::size_type* nOutl )
 {
-    SwNodePtr pNd;
     for( ; *nOutl < pOutlNds->size(); ++(*nOutl) )
-        if( ( pNd = (*pOutlNds)[ *nOutl ])->GetTextNode()->
-                    GetTextColl() == pSplitColl &&
+    {
+        SwNodePtr pNd = (*pOutlNds)[ *nOutl ];
+        if( pNd->GetTextNode()->GetTextColl() == pSplitColl &&
             !pNd->FindTableNode() )
         {
             return pNd;
         }
+    }
     return nullptr;
 }
 
diff --git a/sw/source/core/doc/doclay.cxx b/sw/source/core/doc/doclay.cxx
index 50d9ef0f9850..9929ec8ae599 100644
--- a/sw/source/core/doc/doclay.cxx
+++ b/sw/source/core/doc/doclay.cxx
@@ -492,7 +492,10 @@ static bool lcl_TstFlyRange( const SwPaM* pPam, const SwPosition* pFlyPos,
                      (nPamEndContentIndex > nFlyContentIndex )));
         }
 
-    } while( !bOk && pPam != ( pTmp = pTmp->GetNext() ));
+        if( bOk )
+            break;
+        pTmp = pTmp->GetNext();
+    } while( pPam != pTmp );
     return bOk;
 }
 
@@ -1393,10 +1396,10 @@ const SwFlyFrameFormat* SwDoc::FindFlyByName( const OUString& rName, SwNodeType
     for( auto it = range.first; it != range.second; it++ )
     {
         const SwFrameFormat* pFlyFormat = *it;
-        const SwNodeIndex* pIdx = nullptr;
-        if( RES_FLYFRMFMT == pFlyFormat->Which() && pFlyFormat->GetName() == rName &&
-            nullptr != ( pIdx = pFlyFormat->GetContent().GetContentIdx() ) &&
-            pIdx->GetNode().GetNodes().IsDocNodes() )
+        if( RES_FLYFRMFMT != pFlyFormat->Which() || pFlyFormat->GetName() != rName )
+            continue;
+        const SwNodeIndex* pIdx = pFlyFormat->GetContent().GetContentIdx();
+        if( pIdx && pIdx->GetNode().GetNodes().IsDocNodes() )
         {
             if( nNdTyp != SwNodeType::NONE )
             {
@@ -1457,7 +1460,8 @@ void SwDoc::SetAllUniqueFlyNames()
 
     for( n = GetSpzFrameFormats()->size(); n; )
     {
-        if( RES_FLYFRMFMT == (pFlyFormat = (*GetSpzFrameFormats())[ --n ])->Which() )
+        pFlyFormat = (*GetSpzFrameFormats())[ --n ];
+        if( RES_FLYFRMFMT == pFlyFormat->Which() )
         {
             const OUString& aNm = pFlyFormat->GetName();
             if ( !aNm.isEmpty() )
@@ -1506,10 +1510,9 @@ void SwDoc::SetAllUniqueFlyNames()
 
     for( n = aArr.size(); n; )
     {
-        const SwNodeIndex* pIdx;
-
-        if( nullptr != ( pIdx = ( pFlyFormat = aArr[ --n ])->GetContent().GetContentIdx() )
-            && pIdx->GetNode().GetNodes().IsDocNodes() )
+        pFlyFormat = aArr[ --n ];
+        const SwNodeIndex* pIdx = pFlyFormat->GetContent().GetContentIdx();
+        if( pIdx && pIdx->GetNode().GetNodes().IsDocNodes() )
         {
             switch( GetNodes()[ pIdx->GetIndex() + 1 ]->GetNodeType() )
             {
diff --git a/sw/source/core/doc/docnum.cxx b/sw/source/core/doc/docnum.cxx
index af72d98b70bf..cf3589ceb9cd 100644
--- a/sw/source/core/doc/docnum.cxx
+++ b/sw/source/core/doc/docnum.cxx
@@ -734,14 +734,14 @@ bool SwDoc::GotoOutline(SwPosition& rPos, const OUString& rName, SwRootFrame con
             //#i4533# leading numbers followed by a dot have been remove while
             //searching for the outline position
             //to compensate this they must be removed from the paragraphs text content, too
-            sal_Int32 nPos = 0;
-            OUString sTempNum;
-            while(!sExpandedText.isEmpty() && !(sTempNum = sExpandedText.getToken(0, '.', nPos)).isEmpty() &&
-                    -1 != nPos &&
-                    comphelper::string::isdigitAsciiString(sTempNum))
+            while(!sExpandedText.isEmpty())
             {
+                sal_Int32 nPos = 0;
+                OUString sTempNum = sExpandedText.getToken(0, '.', nPos);
+                if( sTempNum.isEmpty() || -1 == nPos ||
+                    !comphelper::string::isdigitAsciiString(sTempNum))
+                    break;
                 sExpandedText = sExpandedText.copy(nPos);
-                nPos = 0;
             }
 
             if( sExpandedText != sName )
@@ -2222,13 +2222,14 @@ bool SwDoc::MoveParagraphImpl(SwPaM& rPam, long const nOffset,
                 // moved to the next Node
                 for(SwRangeRedline* pTmp : getIDocumentRedlineAccess().GetRedlineTable())
                 {
-                    SwPosition* pPos;
-                    if( ( pPos = &pTmp->GetBound())->nNode == aIdx )
+                    SwPosition* pPos = &pTmp->GetBound();
+                    if( pPos->nNode == aIdx )
                     {
                         ++pPos->nNode;
                         pPos->nContent.Assign( pPos->nNode.GetNode().GetContentNode(),0);
                     }
-                    if( ( pPos = &pTmp->GetBound(false))->nNode == aIdx )
+                    pPos = &pTmp->GetBound(false);
+                    if( pPos->nNode == aIdx )
                     {
                         ++pPos->nNode;
                         pPos->nContent.Assign( pPos->nNode.GetNode().GetContentNode(),0);
diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx
index ebdc7ee3c5ba..b98e89caf48f 100644
--- a/sw/source/core/doc/docredln.cxx
+++ b/sw/source/core/doc/docredln.cxx
@@ -389,15 +389,16 @@ void SwRedlineTable::LOKRedlineNotification(RedlineNotification nType, SwRangeRe
         // So we need to do an own invalidation here. It invalidates text frames containing the redlining
         SwDoc* pDoc = pRedline->GetDoc();
         SwViewShell* pSh;
-        if( pDoc && !pDoc->IsInDtor() &&
-            nullptr != ( pSh = pDoc->getIDocumentLayoutAccess().GetCurrentViewShell()) )
+        if( pDoc && !pDoc->IsInDtor() )
         {
-            for(SwNodeIndex nIdx = pStartPos->nNode; nIdx <= pEndPos->nNode; ++nIdx)
-            {
-                SwContentNode* pContentNode = nIdx.GetNode().GetContentNode();
-                if (pContentNode)
-                    pSh->InvalidateWindows(pContentNode->FindLayoutRect());
-            }
+            pSh = pDoc->getIDocumentLayoutAccess().GetCurrentViewShell();
+            if( pSh )
+                for(SwNodeIndex nIdx = pStartPos->nNode; nIdx <= pEndPos->nNode; ++nIdx)
+                {
+                    SwContentNode* pContentNode = nIdx.GetNode().GetContentNode();
+                    if (pContentNode)
+                        pSh->InvalidateWindows(pContentNode->FindLayoutRect());
+                }
         }
     }
 
@@ -535,8 +536,10 @@ std::vector<SwRangeRedline*> GetAllValidRanges(std::unique_ptr<SwRangeRedline> p
                 pNew = nullptr;
             }
 
-            if( aNewStt >= *pEnd ||
-                nullptr == (pC = rNds.GoNext( &aNewStt.nNode )) )
+            if( aNewStt >= *pEnd )
+                break;
+            pC = rNds.GoNext( &aNewStt.nNode );
+            if( !pC )
                 break;
 
             aNewStt.nContent.Assign( pC, 0 );
@@ -608,10 +611,12 @@ void SwRedlineTable::Remove( size_type nP )
 
     maVector.erase( maVector.begin() + nP );
 
-    SwViewShell* pSh;
-    if( pDoc && !pDoc->IsInDtor() &&
-        nullptr != ( pSh = pDoc->getIDocumentLayoutAccess().GetCurrentViewShell()) )
-        pSh->InvalidateWindows( SwRect( 0, 0, SAL_MAX_INT32, SAL_MAX_INT32 ) );
+    if( pDoc && !pDoc->IsInDtor() )
+    {
+        SwViewShell* pSh = pDoc->getIDocumentLayoutAccess().GetCurrentViewShell();
+        if( pSh )
+            pSh->InvalidateWindows( SwRect( 0, 0, SAL_MAX_INT32, SAL_MAX_INT32 ) );
+    }
 }
 
 void SwRedlineTable::DeleteAndDestroyAll()
diff --git a/sw/source/core/doc/docruby.cxx b/sw/source/core/doc/docruby.cxx
index f333782a5df7..f1ce56a0dd09 100644
--- a/sw/source/core/doc/docruby.cxx
+++ b/sw/source/core/doc/docruby.cxx
@@ -83,8 +83,10 @@ sal_uInt16 SwDoc::FillRubyList( const SwPaM& rPam, SwRubyList& rList )
                 }
             } while( 30 > rList.size() && *aPam.GetPoint() < *pEnd );
         }
-    } while( 30 > rList.size() &&
-        (_pStartCursor = _pStartCursor->GetNext()) != _pStartCursor2 );
+        if( 30 <= rList.size() )
+            break;
+        _pStartCursor = _pStartCursor->GetNext();
+    } while( _pStartCursor != _pStartCursor2 );
 
     return rList.size();
 }
@@ -169,8 +171,10 @@ void SwDoc::SetRubyList( const SwPaM& rPam, const SwRubyList& rList )
                 }
             } while( nListEntry < rList.size() && *aPam.GetPoint() < *pEnd );
         }
-    } while( 30 > rList.size() &&
-        (_pStartCursor = _pStartCursor->GetNext()) != _pStartCursor2 );
+        if( 30 <= rList.size() )
+            break;
+        _pStartCursor = _pStartCursor->GetNext();
+    } while( _pStartCursor != _pStartCursor2 );
 
     GetIDocumentUndoRedo().EndUndo( SwUndoId::SETRUBYATTR, nullptr );
 }
diff --git a/sw/source/core/doc/docsort.cxx b/sw/source/core/doc/docsort.cxx
index bd35fedf13f4..72ac17572ab4 100644
--- a/sw/source/core/doc/docsort.cxx
+++ b/sw/source/core/doc/docsort.cxx
@@ -246,8 +246,11 @@ OUString SwSortBoxElement::GetKey(sal_uInt16 nKey) const
             // Iterate over all the Box's TextNodes
             const SwNode *pNd = nullptr, *pEndNd = pMyBox->GetSttNd()->EndOfSectionNode();
             for( sal_uLong nIdx = pMyBox->GetSttIdx() + 1; pNd != pEndNd; ++nIdx )
-                if( ( pNd = pDoc->GetNodes()[ nIdx ])->IsTextNode() )
+            {
+                pNd = pDoc->GetNodes()[ nIdx ];
+                if( pNd->IsTextNode() )
                     aRetStr.append(pNd->GetTextNode()->GetText());
+            }
         }
     }
     return aRetStr.makeStringAndClear();
@@ -345,11 +348,14 @@ bool SwDoc::SortText(const SwPaM& rPaM, const SwSortOptions& rOpt)
             pRedlPam->GetPoint()->nNode.Assign( aEndIdx.GetNode() );
             pCNd = pRedlPam->GetContentNode();
             sal_Int32 nCLen = 0;
-            if( !pCNd &&
-                nullptr != (pCNd = GetNodes()[ aEndIdx.GetIndex()-1 ]->GetContentNode()))
+            if( !pCNd )
             {
-                nCLen = pCNd->Len();
-                pRedlPam->GetPoint()->nNode.Assign( *pCNd );
+                pCNd = GetNodes()[ aEndIdx.GetIndex()-1 ]->GetContentNode();
+                if( pCNd )
+                {
+                    nCLen = pCNd->Len();
+                    pRedlPam->GetPoint()->nNode.Assign( *pCNd );
+                }
             }
             pRedlPam->GetPoint()->nContent.Assign( pCNd, nCLen );
 
diff --git a/sw/source/core/doc/doctxm.cxx b/sw/source/core/doc/doctxm.cxx
index 524ceeb810c8..83a38236c04d 100644
--- a/sw/source/core/doc/doctxm.cxx
+++ b/sw/source/core/doc/doctxm.cxx
@@ -135,8 +135,8 @@ sal_uInt16 SwDoc::GetCurTOXMark( const SwPosition& rPos,
         if( ( nSttIdx = pHt->GetStart() ) < nCurrentPos )
         {
             // also check the end
-            if( nullptr == ( pEndIdx = pHt->End() ) ||
-                *pEndIdx <= nCurrentPos )
+            pEndIdx = pHt->End();
+            if( nullptr == pEndIdx || *pEndIdx <= nCurrentPos )
                 continue;       // keep searching
         }
         else if( nSttIdx > nCurrentPos )
@@ -1017,12 +1017,16 @@ void SwTOXBaseSection::Update(const SfxItemSet* pAttr,
             const OUString& sPrimKey = rMark.GetPrimaryKey();
             const OUString& sSecKey = rMark.GetSecondaryKey();
             const SwTOXMark* pNextMark = nullptr;
-            while(m_aSortArr.size() > (nCnt + nRange)&&
-                    m_aSortArr[nCnt + nRange]->GetType() == TOX_SORT_INDEX &&
-                    nullptr != (pNextMark = &(m_aSortArr[nCnt + nRange]->pTextMark->GetTOXMark())) &&
-                    pNextMark->GetPrimaryKey() == sPrimKey &&
-                    pNextMark->GetSecondaryKey() == sSecKey)
+            while(m_aSortArr.size() > (nCnt + nRange) &&
+                    m_aSortArr[nCnt + nRange]->GetType() == TOX_SORT_INDEX )
+            {
+                pNextMark = &(m_aSortArr[nCnt + nRange]->pTextMark->GetTOXMark());
+                if( !pNextMark ||
+                    pNextMark->GetPrimaryKey() != sPrimKey ||
+                    pNextMark->GetSecondaryKey() != sSecKey)
+                    break;
                 nRange++;
+            }
         }
         // pass node index of table-of-content section and default page description
         // to method <GenerateText(..)>.
@@ -1653,9 +1657,13 @@ void SwTOXBaseSection::UpdatePageNum()
                         TextFrameIndex const nPos(static_cast<SwTextFrame*>(pFrame)
                             ->MapModelToView(static_cast<SwTextNode const*>(rTOXSource.pNd),
                                 rTOXSource.nPos));
-                        while( nullptr != ( pNext = static_cast<SwTextFrame*>(pFrame->GetFollow()) )
-                                && nPos >= pNext->GetOffset())
+                        for (;;)
+                        {
+                            pNext = static_cast<SwTextFrame*>(pFrame->GetFollow());
+                            if (!pNext || nPos < pNext->GetOffset())
+                                break;
                             pFrame = pNext;
+                        }
                     }
 
                     SwPageFrame*  pTmpPage = pFrame->FindPageFrame();
diff --git a/sw/source/core/doc/ftnidx.cxx b/sw/source/core/doc/ftnidx.cxx
index 099af5bbefe1..07250b97efe2 100644
--- a/sw/source/core/doc/ftnidx.cxx
+++ b/sw/source/core/doc/ftnidx.cxx
@@ -447,13 +447,15 @@ const SwSectionNode* SwUpdFootnoteEndNtAtEnd::FindSectNdWithEndAttr(
 {
     sal_uInt16 nWh = rTextFootnote.GetFootnote().IsEndNote() ?
                         sal_uInt16(RES_END_AT_TXTEND) : sal_uInt16(RES_FTN_AT_TXTEND);
-    sal_uInt16 nVal;
     const SwSectionNode* pNd = rTextFootnote.GetTextNode().FindSectionNode();
-    while( pNd && FTNEND_ATTXTEND_OWNNUMSEQ != ( nVal =
-            static_cast<const SwFormatFootnoteEndAtTextEnd&>(pNd->GetSection().GetFormat()->
-            GetFormatAttr( nWh )).GetValue() ) &&
-            FTNEND_ATTXTEND_OWNNUMANDFMT != nVal )
+    while( pNd )
+    {
+        sal_uInt16 nVal = static_cast<const SwFormatFootnoteEndAtTextEnd&>(pNd->GetSection().GetFormat()->
+                 GetFormatAttr( nWh )).GetValue();
+        if( FTNEND_ATTXTEND_OWNNUMSEQ == nVal || FTNEND_ATTXTEND_OWNNUMANDFMT == nVal )
+            break;
         pNd = pNd->StartOfSectionNode()->FindSectionNode();
+    }
 
     return pNd;
 }
diff --git a/sw/source/core/doc/gctable.cxx b/sw/source/core/doc/gctable.cxx
index ddcf9e20c0f4..8a7105c43a38 100644
--- a/sw/source/core/doc/gctable.cxx
+++ b/sw/source/core/doc/gctable.cxx
@@ -33,14 +33,16 @@ static const SvxBorderLine* GetLineTB( const SvxBoxItem* pBox, bool bTop )
 
 bool SwGCBorder_BoxBrd::CheckLeftBorderOfFormat( const SwFrameFormat& rFormat )
 {
-    const SvxBorderLine* pBrd;
     const SfxPoolItem* pItem;
-    if( SfxItemState::SET == rFormat.GetItemState( RES_BOX, true, &pItem ) &&
-        nullptr != ( pBrd = static_cast<const SvxBoxItem*>(pItem)->GetLeft() ) )
+    if( SfxItemState::SET == rFormat.GetItemState( RES_BOX, true, &pItem ) )
     {
-        if( *pBrdLn == *pBrd )
-            bAnyBorderFnd = true;
-        return true;
+        const SvxBorderLine* pBrd = static_cast<const SvxBoxItem*>(pItem)->GetLeft();
+        if( pBrd )
+        {
+            if( *pBrdLn == *pBrd )
+                bAnyBorderFnd = true;
+            return true;
+        }
     }
     return false;
 }
@@ -102,9 +104,10 @@ static sal_uInt16 lcl_FindEndPosOfBorder( const SwCollectTableLineBoxes& rCollTL
         const SvxBorderLine* pBrd;
         const SwTableBox& rBox = rCollTLB.GetBox( rStt, &nPos );
 
-        if( SfxItemState::SET != rBox.GetFrameFormat()->GetItemState(RES_BOX,true, &pItem )
-            || nullptr == ( pBrd = GetLineTB( static_cast<const SvxBoxItem*>(pItem), bTop ))
-            || *pBrd != rBrdLn )
+        if( SfxItemState::SET != rBox.GetFrameFormat()->GetItemState(RES_BOX,true, &pItem ) )
+            break;
+        pBrd = GetLineTB( static_cast<const SvxBoxItem*>(pItem), bTop );
+        if( !pBrd || *pBrd != rBrdLn )
             break;
         nLastPos = nPos;
     }
@@ -181,22 +184,24 @@ void sw_GC_Line_Border( const SwTableLine* pLine, SwGCLineBorder* pGCPara )
 
             for( SwTableBoxes::size_type i = aBoxes.size(); i; )
             {
-                SwTableBox* pBox;
-                if( SfxItemState::SET == (pBox = aBoxes[ --i ])->GetFrameFormat()->
-                    GetItemState( RES_BOX, true, &pItem ) &&
-                    nullptr != ( pBrd = static_cast<const SvxBoxItem*>(pItem)->GetRight() ) )
+                SwTableBox* pBox = aBoxes[ --i ];
+                if( SfxItemState::SET == pBox->GetFrameFormat()->GetItemState( RES_BOX, true, &pItem ) )
                 {
-                    aBPara.SetBorder( *pBrd );
-                    const SwTableBox* pNextBox = rBoxes[n+1];
-                    if( lcl_GCBorder_ChkBoxBrd_B( pNextBox, &aBPara ) &&
-                        aBPara.IsAnyBorderFound() )
+                    pBrd = static_cast<const SvxBoxItem*>(pItem)->GetRight();
+                    if( pBrd )
                     {
-                        SvxBoxItem aBox( *static_cast<const SvxBoxItem*>(pItem) );
-                        aBox.SetLine( nullptr, SvxBoxItemLine::RIGHT );
-                        if( pGCPara->pShareFormats )
-                            pGCPara->pShareFormats->SetAttr( *pBox, aBox );
-                        else
-                            pBox->ClaimFrameFormat()->SetFormatAttr( aBox );
+                        aBPara.SetBorder( *pBrd );
+                        const SwTableBox* pNextBox = rBoxes[n+1];
+                        if( lcl_GCBorder_ChkBoxBrd_B( pNextBox, &aBPara ) &&
+                            aBPara.IsAnyBorderFound() )
+                        {
+                            SvxBoxItem aBox( *static_cast<const SvxBoxItem*>(pItem) );
+                            aBox.SetLine( nullptr, SvxBoxItemLine::RIGHT );
+                            if( pGCPara->pShareFormats )
+                                pGCPara->pShareFormats->SetAttr( *pBox, aBox );
+                            else
+                                pBox->ClaimFrameFormat()->SetFormatAttr( aBox );
+                        }
                     }
                 }
             }
diff --git a/sw/source/core/doc/number.cxx b/sw/source/core/doc/number.cxx
index 26540353ddba..4bdfe17c4781 100644
--- a/sw/source/core/doc/number.cxx
+++ b/sw/source/core/doc/number.cxx
@@ -514,14 +514,16 @@ void SwNumRule::CheckCharFormats( SwDoc* pDoc )
 {
     for(auto& rpNumFormat : maFormats)
     {
-        SwCharFormat* pFormat;
-        if( rpNumFormat && nullptr != ( pFormat = rpNumFormat->GetCharFormat() ) &&
-            pFormat->GetDoc() != pDoc )
+        if( rpNumFormat )
         {
-            // copy
-            SwNumFormat* pNew = new SwNumFormat( *rpNumFormat );
-            pNew->SetCharFormat( pDoc->CopyCharFormat( *pFormat ) );
-            rpNumFormat.reset(pNew);
+            SwCharFormat* pFormat = rpNumFormat->GetCharFormat();
+            if( pFormat && pFormat->GetDoc() != pDoc )
+            {
+                // copy
+                SwNumFormat* pNew = new SwNumFormat( *rpNumFormat );
+                pNew->SetCharFormat( pDoc->CopyCharFormat( *pFormat ) );
+                rpNumFormat.reset(pNew);
+            }
         }
     }
 }
diff --git a/sw/source/core/doc/tblrwcl.cxx b/sw/source/core/doc/tblrwcl.cxx
index 97150a2309f8..5eb2ff9994b0 100644
--- a/sw/source/core/doc/tblrwcl.cxx
+++ b/sw/source/core/doc/tblrwcl.cxx
@@ -529,9 +529,11 @@ bool SwTable::InsertRow_( SwDoc* pDoc, const SwSelBoxes& rBoxes,
     FndBox_* pFndBox = &aFndBox;
     {
         FndLine_* pFndLine;
-        while( 1 == pFndBox->GetLines().size() &&
-            1 == (pFndLine = pFndBox->GetLines()[0].get())->GetBoxes().size())
+        while( 1 == pFndBox->GetLines().size() )
         {
+            pFndLine = pFndBox->GetLines()[0].get();
+            if( 1 != pFndLine->GetBoxes().size() )
+                break;
             // Don't go down too far! One Line with Box needs to remain!
             FndBox_ *const pTmpBox = pFndLine->GetBoxes().front().get();
             if( !pTmpBox->GetLines().empty() )
@@ -1364,13 +1366,16 @@ static void lcl_Merge_MoveBox(FndBox_ & rFndBox, InsULPara *const pULPara)
                 lcl_CpyBoxes( 0, nPos, *pBoxes, pULPara->pInsLine );
         }
         else                // Right
+        {
             // if there are Boxes behind it, move them
-            if( (nPos = pFndTableBox->GetUpper()->GetBoxPos( pFndTableBox )) +1 < static_cast<sal_uInt16>(pBoxes->size()) )
+            nPos = pFndTableBox->GetUpper()->GetBoxPos( pFndTableBox );
+            if( nPos +1 < static_cast<sal_uInt16>(pBoxes->size()) )
             {
                 nInsPos = pULPara->pInsLine->GetTabBoxes().size();
                 lcl_CpyBoxes( nPos+1, pBoxes->size(),
                                     *pBoxes, pULPara->pInsLine );
             }
+        }
     }
     // Upper/Lower and still deeper?
     else if (!rFndBox.GetLines().empty())
@@ -1431,7 +1436,8 @@ static void lcl_Merge_MoveLine(FndLine_& rFndLine, InsULPara *const pULPara)
             if( pULPara->bUL )  // Upper ?
             {
                 // If there are Lines before it, move them
-                if( 0 != ( nPos = pLines->GetPos( pFndLn )) )
+                nPos = pLines->GetPos( pFndLn );
+                if( 0 != nPos )
                     lcl_CpyLines( 0, nPos, *pLines, pULPara->pInsBox );
             }
             else
@@ -1465,7 +1471,8 @@ static void lcl_Merge_MoveLine(FndLine_& rFndLine, InsULPara *const pULPara)
             if( pULPara->bUL )  // Upper ?
             {
                 // If there are Lines before it, move them
-                if( 0 != ( nPos = pLines->GetPos( pFndLn )) )
+                nPos = pLines->GetPos( pFndLn );
+                if( 0 != nPos )
                     lcl_CpyLines( 0, nPos, *pLines, pLMBox, 0 );
             }
             else
@@ -2189,14 +2196,17 @@ SwTableBox* SwTableLine::FindNextBox( const SwTable& rTable,
     const SwTableLine* pLine = this;            // for M800
     SwTableBox* pBox;
     sal_uInt16 nFndPos;
-    if( !GetTabBoxes().empty() && pSrchBox &&
-        USHRT_MAX != ( nFndPos = GetBoxPos( pSrchBox )) &&
-        nFndPos + 1 != static_cast<sal_uInt16>(GetTabBoxes().size()) )
+    if( !GetTabBoxes().empty() && pSrchBox )
     {
-        pBox = GetTabBoxes()[ nFndPos + 1 ];
-        while( !pBox->GetTabLines().empty() )
-            pBox = pBox->GetTabLines().front()->GetTabBoxes()[0];
-        return pBox;
+        nFndPos = GetBoxPos( pSrchBox );
+        if( USHRT_MAX != nFndPos &&
+            nFndPos + 1 != static_cast<sal_uInt16>(GetTabBoxes().size()) )
+        {
+            pBox = GetTabBoxes()[ nFndPos + 1 ];
+            while( !pBox->GetTabLines().empty() )
+                pBox = pBox->GetTabLines().front()->GetTabBoxes()[0];
+            return pBox;
+        }
     }
 
     if( GetUpper() )
@@ -2237,17 +2247,19 @@ SwTableBox* SwTableLine::FindPreviousBox( const SwTable& rTable,
     const SwTableLine* pLine = this;            // for M800
     SwTableBox* pBox;
     sal_uInt16 nFndPos;
-    if( !GetTabBoxes().empty() && pSrchBox &&
-        USHRT_MAX != ( nFndPos = GetBoxPos( pSrchBox )) &&
-        nFndPos )
+    if( !GetTabBoxes().empty() && pSrchBox )
     {
-        pBox = GetTabBoxes()[ nFndPos - 1 ];
-        while( !pBox->GetTabLines().empty() )
+        nFndPos = GetBoxPos( pSrchBox );
+        if( USHRT_MAX != nFndPos && nFndPos )
         {
-            pLine = pBox->GetTabLines().back();
-            pBox = pLine->GetTabBoxes().back();
+            pBox = GetTabBoxes()[ nFndPos - 1 ];
+            while( !pBox->GetTabLines().empty() )
+            {
+                pLine = pBox->GetTabLines().back();
+                pBox = pLine->GetTabBoxes().back();
+            }
+            return pBox;
         }
-        return pBox;
     }
 
     if( GetUpper() )
@@ -2326,8 +2338,11 @@ static SwTwips lcl_GetDistance( SwTableBox* pBox, bool bLeft )
     bool bFirst = true;
     SwTwips nRet = 0;
     SwTableLine* pLine;
-    while( pBox && nullptr != ( pLine = pBox->GetUpper() ) )
+    while( pBox )
     {
+        pLine = pBox->GetUpper();
+        if( !pLine )
+            break;
         sal_uInt16 nStt = 0, nPos = pLine->GetBoxPos( pBox );
 
         if( bFirst && !bLeft )
diff --git a/sw/source/core/docnode/ndsect.cxx b/sw/source/core/docnode/ndsect.cxx
index 76f1bd7466c4..7ef60935f672 100644
--- a/sw/source/core/docnode/ndsect.cxx
+++ b/sw/source/core/docnode/ndsect.cxx
@@ -154,13 +154,16 @@ SwDoc::InsertSwSection(SwPaM const& rRange, SwSectionData & rNewData,
 {
     const SwNode* pPrvNd = nullptr;
     sal_uInt16 nRegionRet = 0;
-    if( rRange.HasMark() &&
-        0 == ( nRegionRet = IsInsRegionAvailable( rRange, &pPrvNd ) ))
+    if( rRange.HasMark() )
     {
-        // demoted to info because this is called from SwXTextSection::attach,
-        // so it could be invalid input
-        SAL_INFO("sw.core" , "InsertSwSection: rRange overlaps other sections");
-        return nullptr;
+        nRegionRet = IsInsRegionAvailable( rRange, &pPrvNd );
+        if( 0 == nRegionRet )
+        {
+            // demoted to info because this is called from SwXTextSection::attach,
+            // so it could be invalid input
+            SAL_INFO("sw.core" , "InsertSwSection: rRange overlaps other sections");
+            return nullptr;
+        }
     }
 
     // See if the whole Document should be hidden, which we currently are not able to do.
diff --git a/sw/source/core/inc/swcache.hxx b/sw/source/core/inc/swcache.hxx
index 557d9c2a2913..92b678c07e52 100644
--- a/sw/source/core/inc/swcache.hxx
+++ b/sw/source/core/inc/swcache.hxx
@@ -231,8 +231,12 @@ inline SwCacheAccess::SwCacheAccess( SwCache &rC, const void *pOwn, bool bSeek )
     m_pObj( nullptr ),
     m_pOwner( pOwn )
 {
-    if ( bSeek && m_pOwner && nullptr != (m_pObj = m_rCache.Get( m_pOwner )) )
-        m_pObj->Lock();
+    if ( bSeek && m_pOwner )
+    {
+        m_pObj = m_rCache.Get( m_pOwner );
+        if (m_pObj)
+            m_pObj->Lock();
+    }
 }
 
 inline SwCacheAccess::SwCacheAccess( SwCache &rC, const void* nCacheId,
@@ -241,8 +245,12 @@ inline SwCacheAccess::SwCacheAccess( SwCache &rC, const void* nCacheId,
     m_pObj( nullptr ),
     m_pOwner( nCacheId )
 {
-    if ( m_pOwner && nullptr != (m_pObj = m_rCache.Get( m_pOwner, nIndex )) )
-        m_pObj->Lock();
+    if ( m_pOwner )
+    {
+        m_pObj = m_rCache.Get( m_pOwner, nIndex );
+        if (m_pObj)
+            m_pObj->Lock();
+    }
 }
 
 inline SwCacheObj *SwCacheAccess::Get(bool const isDuplicateOwnerAllowed = true)


More information about the Libreoffice-commits mailing list