From a1fb4ac1991a8da2e527b64a0a01a88a8f2959e3 Mon Sep 17 00:00:00 2001 From: Michael Weghorn Date: Fri, 16 Jan 2015 13:50:00 +0000 Subject: 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 Reviewed-by: Noel Grandin --- 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 +-- 7 files changed, 23 insertions(+), 20 deletions(-) (limited to 'sw/source/filter') diff --git a/sw/source/filter/html/htmlflywriter.cxx b/sw/source/filter/html/htmlflywriter.cxx index 34c3f2dd12c1..dfbb5d0db28f 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
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(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(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 ea90350fbc03..2e95323dae21 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 808e0eaaafd7..7da8891a446d 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 dd9ec5e85df5..e39b18e01266 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 be73977dbffc..3c5cb1a34640 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 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 c66c92e69391..b42eb8f67b4a 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 19a6f004adf8..b5918c06f9f7 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()) ) { -- cgit v1.2.3