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

Michael Weghorn m.weghorn at posteo.de
Sun Jan 18 22:18:26 PST 2015


 sw/source/core/view/vnew.cxx            |    4 ++--
 sw/source/core/view/vprint.cxx          |    6 ++++--
 sw/source/filter/html/htmlflywriter.cxx |    6 ++++--
 sw/source/filter/html/htmlforw.cxx      |    3 ++-
 sw/source/filter/html/htmlgrin.cxx      |    9 +++++----
 sw/source/filter/ww8/rtfexport.cxx      |    8 +++++---
 sw/source/filter/ww8/ww8atr.cxx         |    8 ++++----
 sw/source/filter/ww8/ww8par2.cxx        |    6 ++----
 sw/source/filter/ww8/ww8par3.cxx        |    3 +--
 9 files changed, 29 insertions(+), 24 deletions(-)

New commits:
commit a1fb4ac1991a8da2e527b64a0a01a88a8f2959e3
Author: Michael Weghorn <m.weghorn at posteo.de>
Date:   Fri Jan 16 13:50:00 2015 +0000

    fdo#39440 sw: reduce scope of local variables
    
    This addresses some cppcheck warnings.
    
    Change-Id: I7cbc1908d0e3c84f5864db34984d0740db891aef
    Reviewed-on: https://gerrit.libreoffice.org/13962
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noelgrandin at gmail.com>

diff --git a/sw/source/core/view/vnew.cxx b/sw/source/core/view/vnew.cxx
index 6fef158..31d0de4 100644
--- a/sw/source/core/view/vnew.cxx
+++ b/sw/source/core/view/vnew.cxx
@@ -309,14 +309,14 @@ SwViewShell::~SwViewShell()
         if( mpDoc && GetWin() )
         {
             SwNodes& rNds = mpDoc->GetNodes();
-            SwGrfNode *pGNd;
 
             SwStartNode *pStNd;
             SwNodeIndex aIdx( *rNds.GetEndOfAutotext().StartOfSectionNode(), 1 );
             while ( 0 != (pStNd = aIdx.GetNode().GetStartNode()) )
             {
                 ++aIdx;
-                if ( 0 != ( pGNd = aIdx.GetNode().GetGrfNode() ) )
+                SwGrfNode *pGNd = aIdx.GetNode().GetGrfNode();
+                if ( 0 != pGNd )
                 {
                     if( pGNd->IsAnimated() )
                     {
diff --git a/sw/source/core/view/vprint.cxx b/sw/source/core/view/vprint.cxx
index 70eb9c3..ef1d456 100644
--- a/sw/source/core/view/vprint.cxx
+++ b/sw/source/core/view/vprint.cxx
@@ -333,11 +333,13 @@ SwDoc * SwViewShell::FillPrtDoc( SwDoc *pPrtDoc, const SfxPrinter* pPrt)
     if (pPrt)
         pPrtDoc->getIDocumentDeviceAccess().setPrinter( new SfxPrinter(*pPrt), true, true );
 
-    const SfxPoolItem* pCpyItem;
     const SfxItemPool& rPool = GetAttrPool();
     for( sal_uInt16 nWh = POOLATTR_BEGIN; nWh < POOLATTR_END; ++nWh )
-        if( 0 != ( pCpyItem = rPool.GetPoolDefaultItem( nWh ) ) )
+    {
+        const SfxPoolItem* pCpyItem = rPool.GetPoolDefaultItem( nWh );
+        if( 0 != pCpyItem )
             pPrtDoc->GetAttrPool().SetPoolDefaultItem( *pCpyItem );
+    }
 
     // JP 29.07.99 - Bug 67951 - set all Styles from the SourceDoc into
     //                              the PrintDoc - will be replaced!
diff --git a/sw/source/filter/html/htmlflywriter.cxx b/sw/source/filter/html/htmlflywriter.cxx
index 34c3f2d..dfbb5d0 100644
--- a/sw/source/filter/html/htmlflywriter.cxx
+++ b/sw/source/filter/html/htmlflywriter.cxx
@@ -1000,12 +1000,13 @@ void SwHTMLWriter::writeFrameFormatOptions(HtmlWriter& aHtml, const SwFrmFmt& rF
     // Umlauf fuer absatzgeb. Grafiken als <BR CLEAR=...> in den String
     // schreiben
 
-    const sal_Char* pSurroundString = 0;
     if( (nFrameOptions & HTML_FRMOPT_BRCLEAR) &&
         ((FLY_AT_PARA == rFrmFmt.GetAnchor().GetAnchorId()) ||
          (FLY_AT_CHAR == rFrmFmt.GetAnchor().GetAnchorId())) &&
         SfxItemState::SET == rItemSet.GetItemState( RES_SURROUND, true, &pItem ))
     {
+        const sal_Char* pSurroundString = 0;
+
         const SwFmtSurround* pSurround = static_cast<const SwFmtSurround*>(pItem);
         sal_Int16 eHoriOri = rFrmFmt.GetHoriOrient().GetHoriOrient();
         SwSurround eSurround = pSurround->GetSurround();
@@ -1911,11 +1912,12 @@ void SwHTMLWriter::CollectLinkTargets()
 {
     const SwFmtINetFmt* pINetFmt;
     const SwTxtINetFmt* pTxtAttr;
-    const SwTxtNode* pTxtNd;
 
     sal_uInt32 n, nMaxItems = pDoc->GetAttrPool().GetItemCount2( RES_TXTATR_INETFMT );
     for( n = 0; n < nMaxItems; ++n )
     {
+        const SwTxtNode* pTxtNd;
+
         if( 0 != (pINetFmt = static_cast<const SwFmtINetFmt*>(pDoc->GetAttrPool().GetItem2(
             RES_TXTATR_INETFMT, n ) ) ) &&
             0 != ( pTxtAttr = pINetFmt->GetTxtINetFmt()) &&
diff --git a/sw/source/filter/html/htmlforw.cxx b/sw/source/filter/html/htmlforw.cxx
index ea90350..2e95323 100644
--- a/sw/source/filter/html/htmlforw.cxx
+++ b/sw/source/filter/html/htmlforw.cxx
@@ -548,9 +548,10 @@ void SwHTMLWriter::OutHiddenControls(
 {
     sal_Int32 nCount = rFormComps->getCount();
     sal_Int32 nPos = 0;
-    bool bDone = false;
     if( rPropSet.is() )
     {
+        bool bDone = false;
+
         uno::Reference< form::XFormComponent > xFC( rPropSet, uno::UNO_QUERY );
         for( nPos=0; !bDone && nPos < nCount; nPos++ )
         {
diff --git a/sw/source/filter/html/htmlgrin.cxx b/sw/source/filter/html/htmlgrin.cxx
index 808e0ea..7da8891 100644
--- a/sw/source/filter/html/htmlgrin.cxx
+++ b/sw/source/filter/html/htmlgrin.cxx
@@ -759,7 +759,6 @@ IMAGE_SETEVENT:
         pFlyFmt->SetFmtAttr( aURL );
 
         {
-            const SvxMacro *pMacro;
             static const sal_uInt16 aEvents[] = {
                 SFX_EVENT_MOUSEOVER_OBJECT,
                 SFX_EVENT_MOUSECLICK_OBJECT,
@@ -767,8 +766,11 @@ IMAGE_SETEVENT:
                 0 };
 
             for( sal_uInt16 n = 0; aEvents[ n ]; ++n )
-                if( 0 != ( pMacro = rINetFmt.GetMacro( aEvents[ n ] ) ))
+            {
+                const SvxMacro *pMacro = rINetFmt.GetMacro( aEvents[ n ] );
+                if( 0 != pMacro )
                     aMacroItem.SetMacro( aEvents[ n ], *pMacro );
+            }
         }
 
         if ((FLY_AS_CHAR == pFlyFmt->GetAnchor().GetAnchorId()) &&
@@ -1276,10 +1278,9 @@ bool SwHTMLParser::HasCurrentParaBookmarks( bool bIgnoreStack ) const
     // to check the last bookmark
     if( !bIgnoreStack )
     {
-        _HTMLAttr* pAttr;
         for( sal_uInt16 i = aSetAttrTab.size(); i; )
         {
-            pAttr = aSetAttrTab[ --i ];
+            _HTMLAttr* pAttr = aSetAttrTab[ --i ];
             if( RES_FLTR_BOOKMARK == pAttr->pItem->Which() )
             {
                 if( pAttr->GetSttParaIdx() == nNodeIdx )
diff --git a/sw/source/filter/ww8/rtfexport.cxx b/sw/source/filter/ww8/rtfexport.cxx
index dd9ec5e..e39b18e 100644
--- a/sw/source/filter/ww8/rtfexport.cxx
+++ b/sw/source/filter/ww8/rtfexport.cxx
@@ -186,14 +186,16 @@ static bool IsExportNumRule(const SwNumRule& rRule, sal_uInt8* pEnd = 0)
         ;
     ++nEnd;
 
-    const SwNumFmt* pNFmt;
     sal_uInt8 nLvl;
 
     for (nLvl = 0; nLvl < nEnd; ++nLvl)
-        if (SVX_NUM_NUMBER_NONE != (pNFmt = &rRule.Get(nLvl))
-                ->GetNumberingType() || !pNFmt->GetPrefix().isEmpty() ||
+    {
+        const SwNumFmt* pNFmt = &rRule.Get(nLvl);
+        if (SVX_NUM_NUMBER_NONE != pNFmt->GetNumberingType() ||
+                !pNFmt->GetPrefix().isEmpty() ||
                 (!pNFmt->GetSuffix().isEmpty() && pNFmt->GetSuffix() != "."))
             break;
+    }
 
     if (pEnd)
         *pEnd = nEnd;
diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx
index be73977..3c5cb1a 100644
--- a/sw/source/filter/ww8/ww8atr.cxx
+++ b/sw/source/filter/ww8/ww8atr.cxx
@@ -893,15 +893,14 @@ void MSWordExportBase::OutputFormat( const SwFmt& rFmt, bool bPapFmt, bool bChpF
 
 bool MSWordExportBase::HasRefToObject( sal_uInt16 nTyp, const OUString* pName, sal_uInt16 nSeqNo )
 {
-    const SwTxtNode* pNd;
 
     SwFieldType* pType = pDoc->getIDocumentFieldsAccess().GetSysFldType( RES_GETREFFLD );
     SwIterator<SwFmtFld, SwFieldType> aFmtFlds( *pType );
     for ( SwFmtFld* pFmtFld = aFmtFlds.First(); pFmtFld; pFmtFld = aFmtFlds.Next() )
     {
+        const SwTxtNode* pNd = pFmtFld->GetTxtFld()->GetpTxtNode();
         if ( pFmtFld->GetTxtFld() && nTyp == pFmtFld->GetField()->GetSubType() &&
-             0 != ( pNd = pFmtFld->GetTxtFld()->GetpTxtNode() ) &&
-             pNd->GetNodes().IsDocNodes() )
+             0 != pNd && pNd->GetNodes().IsDocNodes() )
         {
             const SwGetRefField& rRFld = *static_cast< SwGetRefField* >( pFmtFld->GetField() );
             switch ( nTyp )
@@ -2032,12 +2031,13 @@ static int lcl_CheckForm( const SwForm& rForm, sal_uInt8 nLvl, OUString& rText )
     // #i21237#
     SwFormTokens aPattern = rForm.GetPattern(nLvl);
     SwFormTokens::iterator aIt = aPattern.begin();
-    bool bPgNumFnd = false;
     FormTokenType eTType;
 
     // #i61362#
     if (! aPattern.empty())
     {
+        bool bPgNumFnd = false;
+
         // #i21237#
         while( ++aIt != aPattern.end() && !bPgNumFnd )
         {
diff --git a/sw/source/filter/ww8/ww8par2.cxx b/sw/source/filter/ww8/ww8par2.cxx
index c66c92e..b42eb8f 100644
--- a/sw/source/filter/ww8/ww8par2.cxx
+++ b/sw/source/filter/ww8/ww8par2.cxx
@@ -1296,13 +1296,11 @@ void WW8TabBandDesc::ProcessSprmTDxaCol(const sal_uInt8* pParamsTDxaCol)
         sal_uInt8 nitcFirst= pParamsTDxaCol[0]; // first col to be changed
         sal_uInt8 nitcLim  = pParamsTDxaCol[1]; // (last col to be changed)+1
         short nDxaCol = (sal_Int16)SVBT16ToShort( pParamsTDxaCol + 2 );
-        short nOrgWidth;
-        short nDelta;
 
         for( int i = nitcFirst; (i < nitcLim) && (i < nWwCols); i++ )
         {
-            nOrgWidth  = nCenter[i+1] - nCenter[i];
-            nDelta     = nDxaCol - nOrgWidth;
+            const short nOrgWidth  = nCenter[i+1] - nCenter[i];
+            const short nDelta = nDxaCol - nOrgWidth;
             for( int j = i+1; j <= nWwCols; j++ )
             {
                 nCenter[j] = nCenter[j] + nDelta;
diff --git a/sw/source/filter/ww8/ww8par3.cxx b/sw/source/filter/ww8/ww8par3.cxx
index 19a6f00..b5918c0 100644
--- a/sw/source/filter/ww8/ww8par3.cxx
+++ b/sw/source/filter/ww8/ww8par3.cxx
@@ -987,10 +987,9 @@ void WW8ListManager::AdjustLVL( sal_uInt8 nLevel, SwNumRule& rNumRule,
     {
         nIdenticalItemSetLevel = nMaxLevel;
         SfxItemIter aIter( *pThisLevelItemSet );
-        SfxItemSet* pLowerLevelItemSet;
         for (sal_uInt8 nLowerLevel = 0; nLowerLevel < nLevel; ++nLowerLevel)
         {
-            pLowerLevelItemSet = rListItemSet[ nLowerLevel ];
+            SfxItemSet* pLowerLevelItemSet = rListItemSet[ nLowerLevel ];
             if(     pLowerLevelItemSet
                 && (pLowerLevelItemSet->Count() == pThisLevelItemSet->Count()) )
             {


More information about the Libreoffice-commits mailing list