From c752d8bdf099b4ba2ef2e145e0d9da42ba7e74d7 Mon Sep 17 00:00:00 2001 From: Michael Weghorn Date: Wed, 14 Jan 2015 18:03:58 +0000 Subject: fdo#39440 svx: reduce scope of local variables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This addresses some cppcheck warnings. Change-Id: I8c63a767c62b3a666ad445a0a3095d1bb1224f5e Reviewed-on: https://gerrit.libreoffice.org/13908 Tested-by: Jenkins Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- svx/source/gallery2/gallery1.cxx | 3 ++- svx/source/gallery2/galtheme.cxx | 2 +- svx/source/svdraw/polypolygoneditor.cxx | 3 ++- svx/source/svdraw/svdedtv2.cxx | 2 +- svx/source/svdraw/svdmark.cxx | 3 +-- svx/source/svdraw/svdmrkv.cxx | 3 +-- svx/source/table/accessibletableshape.cxx | 3 +-- svx/source/tbxctrls/PaletteManager.cxx | 2 +- svx/source/tbxctrls/layctrl.cxx | 3 +-- svx/source/tbxctrls/linectrl.cxx | 3 +-- svx/source/tbxctrls/tbcontrl.cxx | 3 +-- .../textconversiondlgs/chinese_dictionarydialog.cxx | 3 +-- svx/source/unodraw/UnoNameItemTable.cxx | 15 +++++---------- svx/source/unodraw/XPropertyTable.cxx | 15 +++++---------- svx/source/unodraw/unomtabl.cxx | 6 ++---- svx/source/unodraw/unoshape.cxx | 3 +-- svx/source/xoutdev/_xoutbmp.cxx | 3 ++- svx/source/xoutdev/xattr.cxx | 3 +-- 18 files changed, 30 insertions(+), 48 deletions(-) (limited to 'svx') diff --git a/svx/source/gallery2/gallery1.cxx b/svx/source/gallery2/gallery1.cxx index f483f3cf608c..399f145a108c 100644 --- a/svx/source/gallery2/gallery1.cxx +++ b/svx/source/gallery2/gallery1.cxx @@ -305,7 +305,6 @@ void Gallery::ImplLoadSubDirs( const INetURLObject& rBaseURL, bool& rbDirIsReadO INetURLObject aSdgURL( aThmURL); aSdgURL.SetExtension( s_sSDG_EXT ); INetURLObject aSdvURL( aThmURL ); aSdvURL.SetExtension( s_sSDV_EXT ); OUString aTitle; - bool bReadOnly = false; try { @@ -326,6 +325,8 @@ void Gallery::ImplLoadSubDirs( const INetURLObject& rBaseURL, bool& rbDirIsReadO if( !aTitle.isEmpty() ) { + bool bReadOnly = false; + try { aThmCnt.getPropertyValue( s_sIsReadOnly ) >>= bReadOnly; diff --git a/svx/source/gallery2/galtheme.cxx b/svx/source/gallery2/galtheme.cxx index 120e8ac86437..7abdc6d1f611 100644 --- a/svx/source/gallery2/galtheme.cxx +++ b/svx/source/gallery2/galtheme.cxx @@ -702,12 +702,12 @@ GalleryThemeEntry* GalleryTheme::CreateThemeEntry( const INetURLObject& rURL, bo { OUString aThemeName; sal_uInt16 nVersion; - bool bThemeNameFromResource = false; pIStm->ReadUInt16( nVersion ); if( nVersion <= 0x00ff ) { + bool bThemeNameFromResource = false; sal_uInt32 nThemeId = 0; OString aTmpStr = read_uInt16_lenPrefixed_uInt8s_ToOString(*pIStm); diff --git a/svx/source/svdraw/polypolygoneditor.cxx b/svx/source/svdraw/polypolygoneditor.cxx index d01ce7506cf9..594c2ae0f4e0 100644 --- a/svx/source/svdraw/polypolygoneditor.cxx +++ b/svx/source/svdraw/polypolygoneditor.cxx @@ -75,11 +75,12 @@ bool PolyPolygonEditor::SetSegmentsKind(SdrPathSegmentKind eKind, const std::set { // do change at aNewPolyPolygon. Take a look at edge. basegfx::B2DPolygon aCandidate(maPolyPolygon.getB2DPolygon(nPolyNum)); - bool bCandidateChanged(false); const sal_uInt32 nCount(aCandidate.count()); if(nCount && (nPntNum + 1 < nCount || aCandidate.isClosed())) { + bool bCandidateChanged(false); + // it's a valid edge, check control point usage const sal_uInt32 nNextIndex((nPntNum + 1) % nCount); const bool bContolUsed(aCandidate.areControlPointsUsed() diff --git a/svx/source/svdraw/svdedtv2.cxx b/svx/source/svdraw/svdedtv2.cxx index f4e7fb26c8cb..5f7850e4f44d 100644 --- a/svx/source/svdraw/svdedtv2.cxx +++ b/svx/source/svdraw/svdedtv2.cxx @@ -1902,8 +1902,8 @@ SdrObject* SdrEditView::ImpConvertOneObj(SdrObject* pObj, bool bPath, bool bLine void SdrEditView::ImpConvertTo(bool bPath, bool bLineToArea) { - bool bMrkChg=false; if (AreObjectsMarked()) { + bool bMrkChg = false; const size_t nMarkAnz=GetMarkedObjectCount(); sal_uInt16 nDscrID=0; if(bLineToArea) diff --git a/svx/source/svdraw/svdmark.cxx b/svx/source/svdraw/svdmark.cxx index 692219355848..01129c692591 100644 --- a/svx/source/svdraw/svdmark.cxx +++ b/svx/source/svdraw/svdmark.cxx @@ -512,13 +512,12 @@ bool SdrMarkList::InsertPageView(const SdrPageView& rPV) { bool bChgd(false); DeletePageView(rPV); // delete all of them, then append the entire page - SdrObject* pObj; const SdrObjList* pOL = rPV.GetObjList(); const size_t nObjAnz(pOL->GetObjCount()); for(size_t nO = 0; nO < nObjAnz; ++nO) { - pObj = pOL->GetObj(nO); + SdrObject* pObj = pOL->GetObj(nO); bool bDoIt(rPV.IsObjMarkable(pObj)); if(bDoIt) diff --git a/svx/source/svdraw/svdmrkv.cxx b/svx/source/svdraw/svdmrkv.cxx index 66adc70e5167..954d35ad0a30 100644 --- a/svx/source/svdraw/svdmrkv.cxx +++ b/svx/source/svdraw/svdmrkv.cxx @@ -1504,9 +1504,8 @@ bool SdrMarkView::MarkObj(const Rectangle& rRect, bool bUnmark) pObjList=pPV->GetObjList(); Rectangle aFrm1(aR); const size_t nObjAnz = pObjList->GetObjCount(); - SdrObject* pObj; for (size_t nO=0; nOGetObj(nO); + SdrObject* pObj=pObjList->GetObj(nO); Rectangle aRect(pObj->GetCurrentBoundRect()); if (aFrm1.IsInside(aRect)) { if (!bUnmark) { diff --git a/svx/source/table/accessibletableshape.cxx b/svx/source/table/accessibletableshape.cxx index a05e1e0e95ff..35c0ecbeaca5 100644 --- a/svx/source/table/accessibletableshape.cxx +++ b/svx/source/table/accessibletableshape.cxx @@ -959,7 +959,6 @@ void SAL_CALL AccessibleTableShape::selectionChanged (const EventObject& rEvent // Get the currently active cell which is text editing AccessibleCell* AccessibleTableShape::GetActiveAccessibleCell() { - bool bCellEditing = false; Reference< AccessibleCell > xAccCell; AccessibleCell* pAccCell = NULL; SvxTableController* pController = getTableController(); @@ -971,7 +970,7 @@ AccessibleCell* AccessibleTableShape::GetActiveAccessibleCell() ::sdr::table::CellRef xCellRef (pTableObj->getActiveCell()); if ( xCellRef.is() ) { - bCellEditing = xCellRef->IsTextEditActive(); + const bool bCellEditing = xCellRef->IsTextEditActive(); if (bCellEditing) { //Reference< XCell > xCell(xCellRef.get(), UNO_QUERY); diff --git a/svx/source/tbxctrls/PaletteManager.cxx b/svx/source/tbxctrls/PaletteManager.cxx index 33f346e24840..f5ad05161ae4 100644 --- a/svx/source/tbxctrls/PaletteManager.cxx +++ b/svx/source/tbxctrls/PaletteManager.cxx @@ -81,11 +81,11 @@ void PaletteManager::ReloadColorSet(SvxColorValueSet &rColorSet) if( mnCurrentPalette == 0 ) { - const SfxPoolItem* pItem = NULL; XColorListRef pColorList; if ( pDocSh ) { + const SfxPoolItem* pItem = NULL; if ( 0 != ( pItem = pDocSh->GetItem( SID_COLOR_TABLE ) ) ) pColorList = static_cast(pItem)->GetColorList(); } diff --git a/svx/source/tbxctrls/layctrl.cxx b/svx/source/tbxctrls/layctrl.cxx index ce72eb09d7bf..7fd2388ed6fe 100644 --- a/svx/source/tbxctrls/layctrl.cxx +++ b/svx/source/tbxctrls/layctrl.cxx @@ -628,7 +628,6 @@ void ColumnsWindow::MouseButtonUp( const MouseEvent& rMEvt ) void ColumnsWindow::Paint( const Rectangle& ) { long i; - long j; long nLineWidth; Size aSize = GetOutputSizePixel(); @@ -648,7 +647,7 @@ void ColumnsWindow::Paint( const Rectangle& ) DrawRect( Rectangle( i*nMX-1, -1, i*nMX+nMX, aSize.Height()-nTextHeight+1 ) ); - j = 4; + long j = 4; while ( j < aSize.Height()-nTextHeight-4 ) { if ( !(j % 16) ) diff --git a/svx/source/tbxctrls/linectrl.cxx b/svx/source/tbxctrls/linectrl.cxx index de74cd4fe70d..56fd6a670f6d 100644 --- a/svx/source/tbxctrls/linectrl.cxx +++ b/svx/source/tbxctrls/linectrl.cxx @@ -292,14 +292,13 @@ SvxLineEndWindow::SvxLineEndWindow( void SvxLineEndWindow::implInit() { SfxObjectShell* pDocSh = SfxObjectShell::Current(); - const SfxPoolItem* pItem = NULL; SetHelpId( HID_POPUP_LINEEND ); aLineEndSet.SetHelpId( HID_POPUP_LINEEND_CTRL ); if ( pDocSh ) { - pItem = pDocSh->GetItem( SID_LINEEND_LIST ); + const SfxPoolItem* pItem = pDocSh->GetItem( SID_LINEEND_LIST ); if( pItem ) pLineEndList = static_cast( pItem )->GetLineEndList(); diff --git a/svx/source/tbxctrls/tbcontrl.cxx b/svx/source/tbxctrls/tbcontrl.cxx index 27e44e0895bd..e99190ce81a2 100644 --- a/svx/source/tbxctrls/tbcontrl.cxx +++ b/svx/source/tbxctrls/tbcontrl.cxx @@ -2132,11 +2132,10 @@ void SvxStyleToolBoxControl::FillStyleBox() if( pImpl->bSpecModeWriter || pImpl->bSpecModeCalc ) { - bool bInsert; while ( pStyle ) { // sort out default styles - bInsert = true; + bool bInsert = true; OUString aName( pStyle->GetName() ); for( _i = 0 ; _i < nCnt ; ++_i ) { diff --git a/svx/source/unodialogs/textconversiondlgs/chinese_dictionarydialog.cxx b/svx/source/unodialogs/textconversiondlgs/chinese_dictionarydialog.cxx index 7b16e6b44f13..b03bd7656be2 100644 --- a/svx/source/unodialogs/textconversiondlgs/chinese_dictionarydialog.cxx +++ b/svx/source/unodialogs/textconversiondlgs/chinese_dictionarydialog.cxx @@ -197,10 +197,9 @@ DictionaryEntry* DictionaryList::getEntryOnPos( sal_Int32 nPos ) const DictionaryEntry* DictionaryList::getTermEntry( const OUString& rTerm ) const { - DictionaryEntry* pE = 0; for( sal_Int32 nN=GetRowCount(); nN--; ) { - pE = getEntryOnPos( nN ); + DictionaryEntry* pE = getEntryOnPos( nN ); if( pE && rTerm.equals( pE->m_aTerm ) ) return pE; } diff --git a/svx/source/unodraw/UnoNameItemTable.cxx b/svx/source/unodraw/UnoNameItemTable.cxx index 406c685c4fca..224cc0f4eb01 100644 --- a/svx/source/unodraw/UnoNameItemTable.cxx +++ b/svx/source/unodraw/UnoNameItemTable.cxx @@ -127,11 +127,10 @@ void SAL_CALL SvxUnoNameItemTable::removeByName( const OUString& aApiName ) ItemPoolVector::iterator aIter = maItemSetVector.begin(); const ItemPoolVector::iterator aEnd = maItemSetVector.end(); - const NameOrIndex *pItem; while( aIter != aEnd ) { - pItem = static_cast(&((*aIter)->Get( mnWhich ) )); + const NameOrIndex *pItem = static_cast(&((*aIter)->Get( mnWhich ) )); if (sName.equals(pItem->GetName())) { delete (*aIter); @@ -209,13 +208,12 @@ uno::Any SAL_CALL SvxUnoNameItemTable::getByName( const OUString& aApiName ) if (mpModelPool && !aName.isEmpty()) { - const NameOrIndex *pItem; sal_uInt32 nSurrogate; sal_uInt32 nSurrogateCount = mpModelPool ? mpModelPool->GetItemCount2( mnWhich ) : 0; for( nSurrogate = 0; nSurrogate < nSurrogateCount; nSurrogate++ ) { - pItem = static_cast(mpModelPool->GetItem2( mnWhich, nSurrogate )); + const NameOrIndex *pItem = static_cast(mpModelPool->GetItem2( mnWhich, nSurrogate )); if (isValid(pItem) && aName.equals(pItem->GetName())) { @@ -235,13 +233,12 @@ uno::Sequence< OUString > SAL_CALL SvxUnoNameItemTable::getElementNames( ) std::set< OUString > aNameSet; - const NameOrIndex *pItem; const sal_uInt32 nSurrogateCount = mpModelPool ? mpModelPool->GetItemCount2( mnWhich ) : 0; sal_uInt32 nSurrogate; for( nSurrogate = 0; nSurrogate < nSurrogateCount; nSurrogate++ ) { - pItem = static_cast(mpModelPool->GetItem2( mnWhich, nSurrogate )); + const NameOrIndex *pItem = static_cast(mpModelPool->GetItem2( mnWhich, nSurrogate )); if( !isValid( pItem ) ) continue; @@ -276,12 +273,11 @@ sal_Bool SAL_CALL SvxUnoNameItemTable::hasByName( const OUString& aApiName ) sal_uInt32 nSurrogate; - const NameOrIndex *pItem; sal_uInt32 nCount = mpModelPool ? mpModelPool->GetItemCount2( mnWhich ) : 0; for( nSurrogate = 0; nSurrogate < nCount; nSurrogate++ ) { - pItem = static_cast(mpModelPool->GetItem2( mnWhich, nSurrogate )); + const NameOrIndex *pItem = static_cast(mpModelPool->GetItem2( mnWhich, nSurrogate )); if (isValid(pItem) && aName.equals(pItem->GetName())) return sal_True; } @@ -294,13 +290,12 @@ sal_Bool SAL_CALL SvxUnoNameItemTable::hasElements( ) { SolarMutexGuard aGuard; - const NameOrIndex *pItem; sal_uInt32 nSurrogate; const sal_uInt32 nSurrogateCount = mpModelPool ? mpModelPool->GetItemCount2( mnWhich ) : 0; for( nSurrogate = 0; nSurrogate < nSurrogateCount; nSurrogate++ ) { - pItem = static_cast(mpModelPool->GetItem2( mnWhich, nSurrogate )); + const NameOrIndex *pItem = static_cast(mpModelPool->GetItem2( mnWhich, nSurrogate )); if( isValid( pItem ) ) return sal_True; diff --git a/svx/source/unodraw/XPropertyTable.cxx b/svx/source/unodraw/XPropertyTable.cxx index 6697f7bbd24e..7017ece26380 100644 --- a/svx/source/unodraw/XPropertyTable.cxx +++ b/svx/source/unodraw/XPropertyTable.cxx @@ -130,10 +130,9 @@ void SAL_CALL SvxUnoXPropertyTable::removeByName( const OUString& Name ) const long nCount = getCount(); long i; - XPropertyEntry* pEntry; for( i = 0; i < nCount; i++ ) { - pEntry = get( i ); + XPropertyEntry* pEntry = get( i ); if (pEntry && aInternalName.equals(pEntry->GetName())) { if( mpList ) @@ -155,10 +154,9 @@ void SAL_CALL SvxUnoXPropertyTable::replaceByName( const OUString& aName, const const long nCount = getCount(); long i; - XPropertyEntry* pEntry; for( i = 0; i < nCount; i++ ) { - pEntry = get( i ); + XPropertyEntry* pEntry = get( i ); if (pEntry && aInternalName.equals(pEntry->GetName())) { XPropertyEntry* pNewEntry = getEntry( aInternalName, aElement ); @@ -184,10 +182,9 @@ uno::Any SAL_CALL SvxUnoXPropertyTable::getByName( const OUString& aName ) const long nCount = getCount(); long i; - XPropertyEntry* pEntry; for( i = 0; i < nCount; i++ ) { - pEntry = get( i ); + XPropertyEntry* pEntry = get( i ); if (pEntry && aInternalName.equals(pEntry->GetName())) return getAny( pEntry ); @@ -205,10 +202,9 @@ uno::Sequence< OUString > SAL_CALL SvxUnoXPropertyTable::getElementNames() uno::Sequence< OUString > aNames( nCount ); OUString* pNames = aNames.getArray(); long i; - XPropertyEntry* pEntry; for( i = 0; i < nCount; i++ ) { - pEntry = get( i ); + XPropertyEntry* pEntry = get( i ); if (pEntry) *pNames++ = SvxUnogetApiNameForItem(mnWhich, pEntry->GetName()); @@ -226,10 +222,9 @@ sal_Bool SAL_CALL SvxUnoXPropertyTable::hasByName( const OUString& aName ) const long nCount = mpList?mpList->Count():0; long i; - XPropertyEntry* pEntry; for( i = 0; i < nCount; i++ ) { - pEntry = get( i ); + XPropertyEntry* pEntry = get( i ); if (pEntry && aInternalName.equals(pEntry->GetName())) return sal_True; } diff --git a/svx/source/unodraw/unomtabl.cxx b/svx/source/unodraw/unomtabl.cxx index 5ce33fa114fc..7a9d20f3e1b8 100644 --- a/svx/source/unodraw/unomtabl.cxx +++ b/svx/source/unodraw/unomtabl.cxx @@ -196,12 +196,11 @@ void SAL_CALL SvxUnoMarkerTable::removeByName( const OUString& aApiName ) ItemPoolVector::iterator aIter = maItemSetVector.begin(); const ItemPoolVector::iterator aEnd = maItemSetVector.end(); - const NameOrIndex *pItem; const OUString aSearchName( Name ); while( aIter != aEnd ) { - pItem = static_cast(&((*aIter)->Get( XATTR_LINEEND ) )); + const NameOrIndex *pItem = static_cast(&((*aIter)->Get( XATTR_LINEEND ) )); if( pItem->GetName() == aSearchName ) { delete (*aIter); @@ -286,11 +285,10 @@ void SAL_CALL SvxUnoMarkerTable::replaceByName( const OUString& aApiName, const static bool getByNameFromPool( const OUString& rSearchName, SfxItemPool* pPool, sal_uInt16 nWhich, uno::Any& rAny ) { - const NameOrIndex *pItem; const sal_uInt32 nSurrogateCount = pPool ? pPool->GetItemCount2( nWhich ) : 0; for( sal_uInt32 nSurrogate = 0; nSurrogate < nSurrogateCount; nSurrogate++ ) { - pItem = static_cast(pPool->GetItem2( nWhich, nSurrogate )); + const NameOrIndex *pItem = static_cast(pPool->GetItem2( nWhich, nSurrogate )); if( pItem && pItem->GetName() == rSearchName ) { diff --git a/svx/source/unodraw/unoshape.cxx b/svx/source/unodraw/unoshape.cxx index 83c6f77843d4..eff500b171d5 100644 --- a/svx/source/unodraw/unoshape.cxx +++ b/svx/source/unodraw/unoshape.cxx @@ -1606,11 +1606,10 @@ bool SAL_CALL SvxShape::SetFillAttribute( sal_Int32 nWID, const OUString& rName, const OUString aSearchName( aName ); const sal_uInt32 nCount = pPool->GetItemCount2((sal_uInt16)nWID); - const NameOrIndex* pItem; for( sal_uInt32 nSurrogate = 0; nSurrogate < nCount; nSurrogate++ ) { - pItem = static_cast(pPool->GetItem2((sal_uInt16)nWID, nSurrogate)); + const NameOrIndex* pItem = static_cast(pPool->GetItem2((sal_uInt16)nWID, nSurrogate)); if( pItem && ( pItem->GetName() == aSearchName ) ) { rSet.Put( *pItem ); diff --git a/svx/source/xoutdev/_xoutbmp.cxx b/svx/source/xoutdev/_xoutbmp.cxx index 99a92f9b4cdb..d28867ebc435 100644 --- a/svx/source/xoutdev/_xoutbmp.cxx +++ b/svx/source/xoutdev/_xoutbmp.cxx @@ -390,7 +390,6 @@ Bitmap XOutBitmap::DetectEdges( const Bitmap& rBmp, const sal_uInt8 cThreshold ) { const Size aSize( rBmp.GetSizePixel() ); Bitmap aRetBmp; - bool bRet = false; if( ( aSize.Width() > 2L ) && ( aSize.Height() > 2L ) ) { @@ -398,6 +397,8 @@ Bitmap XOutBitmap::DetectEdges( const Bitmap& rBmp, const sal_uInt8 cThreshold ) if( aWorkBmp.Convert( BMP_CONVERSION_8BIT_GREYS ) ) { + bool bRet = false; + Bitmap aDstBmp( aSize, 1 ); BitmapReadAccess* pReadAcc = aWorkBmp.AcquireReadAccess(); BitmapWriteAccess* pWriteAcc = aDstBmp.AcquireWriteAccess(); diff --git a/svx/source/xoutdev/xattr.cxx b/svx/source/xoutdev/xattr.cxx index 8cb9dc225335..372e89e34a56 100644 --- a/svx/source/xoutdev/xattr.cxx +++ b/svx/source/xoutdev/xattr.cxx @@ -145,10 +145,9 @@ OUString NameOrIndex::CheckNamedItem( const NameOrIndex* pCheckItem, const sal_u { const sal_uInt32 nCount = pPool1->GetItemCount2( nWhich ); - const NameOrIndex *pItem; for( sal_uInt32 nSurrogate = 0; nSurrogate < nCount; nSurrogate++ ) { - pItem = static_cast(pPool1->GetItem2( nWhich, nSurrogate )); + const NameOrIndex *pItem = static_cast(pPool1->GetItem2( nWhich, nSurrogate )); if( pItem && ( pItem->GetName() == pCheckItem->GetName() ) ) { -- cgit