[Libreoffice-commits] core.git: stoc/source svl/source svtools/source

Michael Weghorn m.weghorn at posteo.de
Sun Jan 11 22:45:46 PST 2015


 stoc/source/defaultregistry/defaultregistry.cxx    |    6 ++----
 stoc/source/implementationregistration/implreg.cxx |    3 +--
 svl/source/passwordcontainer/passwordcontainer.cxx |    5 ++---
 svl/source/svdde/ddesvr.cxx                        |    6 ++----
 svtools/source/contnr/treelistbox.cxx              |   10 ++++------
 svtools/source/contnr/treelistentry.cxx            |    3 +--
 svtools/source/control/calendar.cxx                |    9 +++------
 svtools/source/control/headbar.cxx                 |    3 ++-
 svtools/source/control/roadmap.cxx                 |   10 +++-------
 svtools/source/control/ruler.cxx                   |   13 +++++--------
 svtools/source/control/tabbar.cxx                  |    9 ++++-----
 svtools/source/control/toolbarmenu.cxx             |    2 +-
 svtools/source/misc/imap.cxx                       |    6 +++---
 svtools/source/misc/imap2.cxx                      |    6 ++----
 14 files changed, 35 insertions(+), 56 deletions(-)

New commits:
commit d5f48d742ac1fea9fd341244bbcea09bcd78b476
Author: Michael Weghorn <m.weghorn at posteo.de>
Date:   Sat Jan 10 15:52:17 2015 +0100

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

diff --git a/stoc/source/defaultregistry/defaultregistry.cxx b/stoc/source/defaultregistry/defaultregistry.cxx
index 37ff4a47..aff3f14 100644
--- a/stoc/source/defaultregistry/defaultregistry.cxx
+++ b/stoc/source/defaultregistry/defaultregistry.cxx
@@ -822,7 +822,6 @@ Sequence< Reference< XRegistryKey > > SAL_CALL NestedKeyImpl::openKeys(  )
     }
 
     Sequence< Reference<XRegistryKey> > retSeq(local + def - len);
-    bool                            insert = true;
     OUString                            name;
     sal_Int32                           lastIndex;
 
@@ -838,7 +837,7 @@ Sequence< Reference< XRegistryKey > > SAL_CALL NestedKeyImpl::openKeys(  )
     sal_uInt32 k = local;
     for (i=0; i < def; i++)
     {
-        insert = true;
+        bool insert = true;
 
         for (j=0 ; j < local; j++)
         {
@@ -902,7 +901,6 @@ Sequence< OUString > SAL_CALL NestedKeyImpl::getKeyNames(  )
     }
 
     Sequence<OUString>  retSeq(local + def - len);
-    bool            insert = true;
 
     for (i=0; i < local; i++)
     {
@@ -912,7 +910,7 @@ Sequence< OUString > SAL_CALL NestedKeyImpl::getKeyNames(  )
     sal_uInt32 k = local;
     for (i=0; i < def; i++)
     {
-        insert = true;
+        bool insert = true;
 
         for (j=0 ; j < local; j++)
         {
diff --git a/stoc/source/implementationregistration/implreg.cxx b/stoc/source/implementationregistration/implreg.cxx
index d0627d2..90d3ce2 100644
--- a/stoc/source/implementationregistration/implreg.cxx
+++ b/stoc/source/implementationregistration/implreg.cxx
@@ -505,13 +505,12 @@ static void deleteUserLink(const Reference < XRegistryKey >& xRootKey,
         linkName + spool().colon_old );
     if (xOldKey.is())
     {
-        bool hasNoImplementations = false;
-
         if (xOldKey->getValueType() == RegistryValueType_ASCIILIST)
         {
             Sequence<OUString> implEntries = xOldKey->getAsciiListValue();
             sal_Int32 length = implEntries.getLength();
             sal_Int32 equals = 0;
+            bool hasNoImplementations = false;
 
             for (sal_Int32 i = 0; i < length; i++)
             {
diff --git a/svl/source/passwordcontainer/passwordcontainer.cxx b/svl/source/passwordcontainer/passwordcontainer.cxx
index aadd1f98..6588a4d 100644
--- a/svl/source/passwordcontainer/passwordcontainer.cxx
+++ b/svl/source/passwordcontainer/passwordcontainer.cxx
@@ -50,14 +50,13 @@ using namespace com::sun::star::ucb;
 static OUString createIndex( vector< OUString > lines )
 {
     OString aResult;
-    const sal_Char* pLine;
 
     for( unsigned int i = 0; i < lines.size(); i++ )
     {
         if( i )
             aResult += OString( "__" );
         OString line = OUStringToOString( lines[i], RTL_TEXTENCODING_UTF8 );
-        pLine = line.getStr();
+        const sal_Char* pLine = line.getStr();
 
         while( *pLine )
         {
@@ -852,7 +851,6 @@ OUString PasswordContainer::GetMasterPassword( const Reference< XInteractionHand
     if( m_aMasterPasswd.isEmpty() && aHandler.is() )
     {
         OUString aEncodedMP;
-        bool bAskAgain = false;
         bool bDefaultPassword = false;
 
         if( !m_pStorageFile->getEncodedMP( aEncodedMP ) )
@@ -865,6 +863,7 @@ OUString PasswordContainer::GetMasterPassword( const Reference< XInteractionHand
 
         if ( !bDefaultPassword )
         {
+            bool bAskAgain = false;
             do {
                 bAskAgain = false;
 
diff --git a/svl/source/svdde/ddesvr.cxx b/svl/source/svdde/ddesvr.cxx
index 24492be..1dd7110 100644
--- a/svl/source/svdde/ddesvr.cxx
+++ b/svl/source/svdde/ddesvr.cxx
@@ -372,11 +372,10 @@ found:
 
 DdeService* DdeInternal::FindService( HSZ hService )
 {
-    DdeService*  s;
     DdeServices& rSvc = DdeService::GetServices();
     for (DdeServices::iterator aI = rSvc.begin(); aI != rSvc.end(); ++aI)
     {
-        s = *aI;
+        DdeService*  s = *aI;
         if ( *s->pName == hService )
             return s;
     }
@@ -932,12 +931,11 @@ OUString DdeService::Topics()
 OUString DdeService::Formats()
 {
     OUString    s;
-    long        f;
     short       n = 0;
 
     for (size_t i = 0; i < aFormats.size(); ++i, ++n)
     {
-        f = aFormats[ i ];
+        long f = aFormats[ i ];
         if ( n )
             s += "\t";
 
diff --git a/svtools/source/contnr/treelistbox.cxx b/svtools/source/contnr/treelistbox.cxx
index e9c0030..28de122 100644
--- a/svtools/source/contnr/treelistbox.cxx
+++ b/svtools/source/contnr/treelistbox.cxx
@@ -1502,11 +1502,10 @@ OUString SvTreeListBox::SearchEntryTextWithHeadTitle( SvTreeListEntry* pEntry )
     sal_uInt16 nCount = pEntry->ItemCount();
     sal_uInt16 nCur = 0;
     sal_uInt16 nHeaderCur = 0;
-    SvLBoxItem* pItem;
     while( nCur < nCount )
     {
         // MT: SV_ITEM_ID_EXTENDRLBOXSTRING / GetExtendText() was in use in IA2 cws, but only used in sc: ScSolverOptionsString. Needed?
-        pItem = pEntry->GetItem( nCur );
+        SvLBoxItem* pItem = pEntry->GetItem( nCur );
         if ( (pItem->GetType() == SV_ITEM_ID_LBOXSTRING ) &&
              !static_cast<SvLBoxString*>( pItem )->GetText().isEmpty() )
         {
@@ -1775,13 +1774,12 @@ void SvTreeListBox::InitEntry(SvTreeListEntry* pEntry,
     const OUString& aStr, const Image& aCollEntryBmp, const Image& aExpEntryBmp,
     SvLBoxButtonKind eButtonKind)
 {
-    SvLBoxButton* pButton;
     SvLBoxString* pString;
     SvLBoxContextBmp* pContextBmp;
 
     if( nTreeFlags & TREEFLAG_CHKBTN )
     {
-        pButton= new SvLBoxButton( pEntry,eButtonKind,0,pCheckButtonData );
+        SvLBoxButton* pButton= new SvLBoxButton( pEntry,eButtonKind,0,pCheckButtonData );
         pEntry->AddItem( pButton );
     }
 
@@ -2319,14 +2317,14 @@ short SvTreeListBox::GetHeightOffset(const vcl::Font& /* rFont */, Size& aSizeLo
 
 void SvTreeListBox::SetEntryHeight( SvTreeListEntry* pEntry )
 {
-    short nHeight, nHeightMax=0;
+    short nHeightMax=0;
     sal_uInt16 nCount = pEntry->ItemCount();
     sal_uInt16 nCur = 0;
     SvViewDataEntry* pViewData = GetViewDataEntry( pEntry );
     while( nCur < nCount )
     {
         SvLBoxItem* pItem = pEntry->GetItem( nCur );
-        nHeight = (short)(pItem->GetSize( pViewData, nCur ).Height());
+        short nHeight = (short)(pItem->GetSize( pViewData, nCur ).Height());
         if( nHeight > nHeightMax )
             nHeightMax = nHeight;
         nCur++;
diff --git a/svtools/source/contnr/treelistentry.cxx b/svtools/source/contnr/treelistentry.cxx
index e294b99..e8bf2de 100644
--- a/svtools/source/contnr/treelistentry.cxx
+++ b/svtools/source/contnr/treelistentry.cxx
@@ -112,13 +112,12 @@ void SvTreeListEntry::Clone(SvTreeListEntry* pSource)
     nListPos |= ( pSource->nListPos & 0x7fffffff);
     nAbsPos     = pSource->nAbsPos;
 
-    SvLBoxItem* pNewItem;
     maItems.clear();
     ItemsType::iterator it = pSource->maItems.begin(), itEnd = pSource->maItems.end();
     for (; it != itEnd; ++it)
     {
         SvLBoxItem* pItem = &(*it);
-        pNewItem = pItem->Create();
+        SvLBoxItem* pNewItem = pItem->Create();
         pNewItem->Clone(pItem);
         maItems.push_back(pNewItem);
     }
diff --git a/svtools/source/control/calendar.cxx b/svtools/source/control/calendar.cxx
index 45bd8aa..fa20f99 100644
--- a/svtools/source/control/calendar.cxx
+++ b/svtools/source/control/calendar.cxx
@@ -506,10 +506,8 @@ sal_uInt16 Calendar::ImplHitTest( const Point& rPos, Date& rDate ) const
     else if ( maNextRect.IsInside( rPos ) )
         return CALENDAR_HITTEST_NEXT;
 
-    long        nX;
     long        nY;
     long        nOffX;
-    long        nYMonth;
     sal_uInt16      nDay;
     DayOfWeek   eStartDay = ImplGetWeekStart();
 
@@ -520,8 +518,8 @@ sal_uInt16 Calendar::ImplHitTest( const Point& rPos, Date& rDate ) const
         if ( rPos.Y() < nY )
             return 0;
 
-        nX = 0;
-        nYMonth = nY+mnMonthHeight;
+        long nX = 0;
+        long nYMonth = nY+mnMonthHeight;
         for ( long j = 0; j < mnMonthPerLine; j++ )
         {
             if ( (rPos.X() < nX) && (rPos.Y() < nYMonth) )
@@ -802,7 +800,6 @@ void Calendar::ImplDraw( bool bPaint )
     Size        aOutSize = GetOutputSizePixel();
     long        i;
     long        j;
-    long        nX;
     long        nY;
     long        nDeltaX;
     long        nDeltaY;
@@ -868,7 +865,7 @@ void Calendar::ImplDraw( bool bPaint )
             DrawLine( aSepPos1, aSepPos2 );
         }
 
-        nX = 0;
+        long nX = 0;
         for ( j = 0; j < mnMonthPerLine; j++ )
         {
             nMonth  = aDate.GetMonth();
diff --git a/svtools/source/control/headbar.cxx b/svtools/source/control/headbar.cxx
index e3d4554..8913ca0 100644
--- a/svtools/source/control/headbar.cxx
+++ b/svtools/source/control/headbar.cxx
@@ -776,12 +776,13 @@ void HeaderBar::ImplStartDrag( const Point& rMousePos, bool bCommand )
 
 void HeaderBar::ImplDrag( const Point& rMousePos )
 {
-    bool        bNewOutDrag;
     sal_uInt16  nPos = GetItemPos( mnCurItemId );
 
     mnDragPos = rMousePos.X()-mnMouseOff;
     if ( mbItemMode )
     {
+        bool bNewOutDrag;
+
         Rectangle aItemRect = ImplGetItemRect( nPos );
         if ( aItemRect.IsInside( rMousePos ) )
             bNewOutDrag = false;
diff --git a/svtools/source/control/roadmap.cxx b/svtools/source/control/roadmap.cxx
index 0933908..7d8705e 100644
--- a/svtools/source/control/roadmap.cxx
+++ b/svtools/source/control/roadmap.cxx
@@ -314,13 +314,12 @@ namespace svt
         const HL_Vector& rItems = m_pImpl->getHyperLabels();
         if ( _nIndex < (ItemIndex)rItems.size() )
         {
-            RoadmapItem* pItem = NULL;
             for (   HL_Vector::const_iterator i = rItems.begin() + _nIndex;
                     i != rItems.end();
                     ++i, ++_nIndex
                 )
             {
-                pItem = *i;
+                RoadmapItem* pItem = *i;
 
                 pItem->SetIndex( _nIndex );
                 pItem->SetPosition( GetPreviousHyperLabel( _nIndex ) );
@@ -463,12 +462,10 @@ namespace svt
 
     RoadmapTypes::ItemId ORoadmap::GetNextAvailableItemId( ItemIndex _nNewIndex )
     {
-        RoadmapItem* pItem = NULL;
-
         ItemIndex searchIndex = ++_nNewIndex;
         while ( searchIndex < m_pImpl->getItemCount() )
         {
-            pItem = GetByIndex( searchIndex );
+            RoadmapItem* pItem = GetByIndex( searchIndex );
             if ( pItem->IsEnabled() )
                 return pItem->GetID( );
 
@@ -480,11 +477,10 @@ namespace svt
 
     RoadmapTypes::ItemId ORoadmap::GetPreviousAvailableItemId( ItemIndex _nNewIndex )
     {
-        RoadmapItem* pItem = NULL;
         ItemIndex searchIndex = --_nNewIndex;
         while ( searchIndex > -1 )
         {
-            pItem = GetByIndex( searchIndex );
+            RoadmapItem* pItem = GetByIndex( searchIndex );
             if ( pItem->IsEnabled() )
                 return pItem->GetID( );
 
diff --git a/svtools/source/control/ruler.cxx b/svtools/source/control/ruler.cxx
index 1656813..43584cd 100644
--- a/svtools/source/control/ruler.cxx
+++ b/svtools/source/control/ruler.cxx
@@ -371,7 +371,6 @@ void Ruler::ImplInvertLines( bool bErase )
          mbActive && !mbDrag && !mbFormat &&
          !(mnUpdateFlags & RULER_UPDATE_LINES) )
     {
-        long n;
         long nNullWinOff = mpData->nNullVirOff + mnVirOff;
         long nRulX1      = mpData->nRulVirOff  + mnVirOff;
         long nRulX2      = nRulX1 + mpData->nRulWidth;
@@ -387,7 +386,7 @@ void Ruler::ImplInvertLines( bool bErase )
         // Draw lines
         for ( sal_uInt32 i = 0; i < mpData->pLines.size(); i++ )
         {
-            n = mpData->pLines[i].nPos + nNullWinOff;
+            const long n = mpData->pLines[i].nPos + nNullWinOff;
             if ( (n >= nRulX1) && (n < nRulX2) )
             {
                 if ( mnWinStyle & WB_HORZ )
@@ -437,14 +436,11 @@ void Ruler::ImplDrawTicks( long nMin, long nMax, long nStart, long nTop, long nB
     long nTickLength2 = nTickLength3 * 0.66;
     long nTickLength1 = nTickLength2 * 0.66;
 
-    long n = 0;
     double nTick4 = aImplRulerUnitTab[mnUnitIndex].nTick4;
-    double nTick3 = 0;
     double nTick2 = 0;
     double nTickCount = aImplRulerUnitTab[mnUnitIndex].nTick1;
     double nTickUnit = 0;
     long nTickWidth;
-    long nTickLength;
     bool bNoTicks = false;
 
     double nAcceptanceDelta = 0.0001;
@@ -544,7 +540,9 @@ void Ruler::ImplDrawTicks( long nMin, long nMax, long nStart, long nTop, long nB
 
     if ( !bNoTicks )
     {
+        long n = 0;
         double nTick = 0.0;
+        double nTick3 = 0;
 
         if ( ( mnUnitIndex != RULER_UNIT_CHAR ) && ( mnUnitIndex != RULER_UNIT_LINE ) )
         {
@@ -617,7 +615,7 @@ void Ruler::ImplDrawTicks( long nMin, long nMax, long nStart, long nTop, long nB
                 // Tick/Tick2 - Output (Strokes)
                 else
                 {
-                    nTickLength = nTickLength1;
+                    long nTickLength = nTickLength1;
 
                     aStep = (nTick / nTick2);
                     aRest = std::abs(aStep - std::floor(aStep));
@@ -1443,7 +1441,6 @@ bool Ruler::ImplHitTest( const Point& rPos, RulerSelection* pHitTest,
     long        nX;
     long        nY;
     long        n1;
-    long        n2;
 
     if ( !mbActive )
         return false;
@@ -1596,7 +1593,7 @@ bool Ruler::ImplHitTest( const Point& rPos, RulerSelection* pHitTest,
     for ( i = mpData->pBorders.size(); i; i-- )
     {
         n1 = mpData->pBorders[i-1].nPos;
-        n2 = n1 + mpData->pBorders[i-1].nWidth;
+        long n2 = n1 + mpData->pBorders[i-1].nWidth;
 
         // borders have at least 3 pixel padding
         if ( !mpData->pBorders[i-1].nWidth )
diff --git a/svtools/source/control/tabbar.cxx b/svtools/source/control/tabbar.cxx
index e3a6f15..629e52d6 100644
--- a/svtools/source/control/tabbar.cxx
+++ b/svtools/source/control/tabbar.cxx
@@ -904,11 +904,12 @@ void TabBar::MouseButtonDown( const MouseEvent& rMEvt )
         if ( nSelId )
         {
             sal_uInt16  nPos = GetPagePos( nSelId );
-            bool        bSelectTab = false;
             pItem = (*mpItemList)[ nPos ];
 
             if ( pItem->mbEnable )
             {
+                bool bSelectTab = false;
+
                 if ( (rMEvt.GetMode() & MouseEventModifiers::MULTISELECT) && (mnWinStyle & WB_MULTISELECT) )
                 {
                     if ( nSelId != mnCurPageId )
@@ -1672,7 +1673,6 @@ void TabBar::ImplPrePaint()
     if (!nItemCount)
         return;
 
-    ImplTabBarItem* pItem;
 
     // tabbar should be formatted
     ImplFormat();
@@ -1684,7 +1684,7 @@ void TabBar::ImplPrePaint()
 
         if ( mnCurPageId && (mnFirstPos == 0) && !mbDropPos )
         {
-            pItem = (*mpItemList)[ GetPagePos( mnCurPageId ) ];
+            ImplTabBarItem* pItem = (*mpItemList)[ GetPagePos( mnCurPageId ) ];
             if ( pItem->maRect.IsEmpty() )
             {
                 // set mbDropPos (or misuse) to prevent Invalidate()
@@ -1823,10 +1823,9 @@ Color TabBar::GetTabBgColor( sal_uInt16 nPageId ) const
 void TabBar::SetTabBgColor( sal_uInt16 nPageId, const Color& aTabBgColor )
 {
     sal_uInt16 nPos = GetPagePos( nPageId );
-    ImplTabBarItem* pItem;
     if ( nPos != PAGE_NOT_FOUND )
     {
-        pItem = (*mpItemList)[ nPos ];
+        ImplTabBarItem* pItem = (*mpItemList)[ nPos ];
         if ( aTabBgColor != Color( COL_AUTO )  )
         {
             pItem->maTabBgColor = aTabBgColor;
diff --git a/svtools/source/control/toolbarmenu.cxx b/svtools/source/control/toolbarmenu.cxx
index 825221d..beb142b 100644
--- a/svtools/source/control/toolbarmenu.cxx
+++ b/svtools/source/control/toolbarmenu.cxx
@@ -987,11 +987,11 @@ void ToolbarMenu::MouseMove( const MouseEvent& rMEvt )
 
 void ToolbarMenu::implHighlightEntry( const MouseEvent& rMEvt, bool /*bMBDown*/ )
 {
-    long nY = 0;
     long nMouseY = rMEvt.GetPosPixel().Y();
     Size aOutSz = GetOutputSizePixel();
     if ( ( nMouseY >= 0 ) && ( nMouseY < aOutSz.Height() ) )
     {
+        long nY = 0;
         bool bHighlighted = false;
 
         const int nEntryCount = mpImpl->maEntryVector.size();
diff --git a/svtools/source/misc/imap.cxx b/svtools/source/misc/imap.cxx
index 37f794c..d3174ee 100644
--- a/svtools/source/misc/imap.cxx
+++ b/svtools/source/misc/imap.cxx
@@ -537,10 +537,11 @@ bool IMapPolygonObject::IsEqual( const IMapPolygonObject& rEqObj )
         const Polygon&   rEqPoly = rEqObj.aPoly;
         const sal_uInt16 nCount = aPoly.GetSize();
         const sal_uInt16 nEqCount = rEqPoly.GetSize();
-        bool             bDifferent = false;
 
         if ( nCount == nEqCount )
         {
+            bool bDifferent = false;
+
             for ( sal_uInt16 i = 0; i < nCount; i++ )
             {
                 if ( aPoly[ i ] != rEqPoly[ i ] )
@@ -865,12 +866,11 @@ void ImageMap::Scale( const Fraction& rFracX, const Fraction& rFracY )
 
 void ImageMap::ImpWriteImageMap( SvStream& rOStm, const OUString& rBaseURL ) const
 {
-    IMapObject* pObj;
     size_t      nCount = maList.size();
 
     for ( size_t i = 0; i < nCount; i++ )
     {
-        pObj = maList[ i ];
+        IMapObject* pObj = maList[ i ];
         pObj->Write( rOStm, rBaseURL );
     }
 }
diff --git a/svtools/source/misc/imap2.cxx b/svtools/source/misc/imap2.cxx
index 3164f8a..5edf203 100644
--- a/svtools/source/misc/imap2.cxx
+++ b/svtools/source/misc/imap2.cxx
@@ -157,12 +157,11 @@ void ImageMap::Write( SvStream& rOStm, sal_uLong nFormat, const OUString& rBaseU
 
 void ImageMap::ImpWriteCERN( SvStream& rOStm, const OUString& rBaseURL ) const
 {
-    IMapObject* pObj;
     size_t      nCount = maList.size();
 
     for ( size_t i = 0; i < nCount; i++ )
     {
-        pObj = maList[ i ];
+        IMapObject* pObj = maList[ i ];
 
         switch( pObj->GetType() )
         {
@@ -186,12 +185,11 @@ void ImageMap::ImpWriteCERN( SvStream& rOStm, const OUString& rBaseURL ) const
 
 void ImageMap::ImpWriteNCSA( SvStream& rOStm, const OUString& rBaseURL  ) const
 {
-    IMapObject* pObj;
     size_t      nCount = maList.size();
 
     for ( size_t i = 0; i < nCount; i++ )
     {
-        pObj = maList[ i ];
+        IMapObject* pObj = maList[ i ];
 
         switch( pObj->GetType() )
         {


More information about the Libreoffice-commits mailing list