[Libreoffice-commits] core.git: pyuno/source sal/osl sal/textenc sax/source sc/source

Michael Weghorn m.weghorn at posteo.de
Sat Aug 22 06:04:40 PDT 2015


 pyuno/source/module/pyuno_iterator.cxx  |    3 ++-
 sal/osl/unx/random.cxx                  |    2 +-
 sal/textenc/tcvtmb.cxx                  |    3 +--
 sax/source/tools/converter.cxx          |    3 ++-
 sc/source/core/data/compressedarray.cxx |    3 +--
 sc/source/core/data/document.cxx        |    3 +--
 sc/source/core/data/dptabres.cxx        |    6 ++----
 sc/source/core/tool/addincol.cxx        |   27 ++++++++++++---------------
 sc/source/core/tool/interpr1.cxx        |    3 ++-
 9 files changed, 24 insertions(+), 29 deletions(-)

New commits:
commit 7e318570dc0c0878bfd2a960230a26f7e5fe2bcf
Author: Michael Weghorn <m.weghorn at posteo.de>
Date:   Sat Aug 22 13:08:41 2015 +0200

    tdf#39440 reduce scope of local variables
    
    This addresses some cppcheck warnings.
    
    Change-Id: Ie492fb9c106b37c3fe7b0105236ad6315f4f159e
    Reviewed-on: https://gerrit.libreoffice.org/17921
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>

diff --git a/pyuno/source/module/pyuno_iterator.cxx b/pyuno/source/module/pyuno_iterator.cxx
index 9fa7971..58c6f50 100644
--- a/pyuno/source/module/pyuno_iterator.cxx
+++ b/pyuno/source/module/pyuno_iterator.cxx
@@ -63,11 +63,12 @@ PyObject* PyUNO_iterator_next( PyObject *self )
     PyUNO_iterator* me = reinterpret_cast<PyUNO_iterator*>(self);
 
     Runtime runtime;
-    bool hasMoreElements = false;
     Any aRet;
 
     try
     {
+        bool hasMoreElements = false;
+
         {
             PyThreadDetach antiguard;
 
diff --git a/sal/osl/unx/random.cxx b/sal/osl/unx/random.cxx
index 04333a2..a0fb73c 100644
--- a/sal/osl/unx/random.cxx
+++ b/sal/osl/unx/random.cxx
@@ -14,7 +14,6 @@
 
 int osl_get_system_random_data(char* buffer, size_t desired_len)
 {
-    ssize_t nb_read;
     int fd;
 
     assert(buffer);
@@ -23,6 +22,7 @@ int osl_get_system_random_data(char* buffer, size_t desired_len)
     {
         while(desired_len)
         {
+            ssize_t nb_read;
             if ((nb_read = read(fd, buffer, desired_len)) == -1)
             {
                 if (errno != EINTR)
diff --git a/sal/textenc/tcvtmb.cxx b/sal/textenc/tcvtmb.cxx
index 75e5b7f..cce84c1 100644
--- a/sal/textenc/tcvtmb.cxx
+++ b/sal/textenc/tcvtmb.cxx
@@ -40,7 +40,6 @@ sal_Size ImplDBCSToUnicode( const void* pData, SAL_UNUSED_PARAMETER void*,
                             sal_uInt32 nFlags, sal_uInt32* pInfo,
                             sal_Size* pSrcCvtBytes )
 {
-    unsigned char                   cLead;
     unsigned char                   cTrail;
     sal_Unicode                 cConv;
     const ImplDBCSToUniLeadTab* pLeadEntry;
@@ -54,7 +53,7 @@ sal_Size ImplDBCSToUnicode( const void* pData, SAL_UNUSED_PARAMETER void*,
     pEndSrcBuf  = pSrcBuf+nSrcBytes;
     while ( pSrcBuf < pEndSrcBuf )
     {
-        cLead = (unsigned char)*pSrcBuf;
+        unsigned char cLead = (unsigned char)*pSrcBuf;
 
         /* get entry for the lead byte */
         pLeadEntry = pLeadTab+cLead;
diff --git a/sax/source/tools/converter.cxx b/sax/source/tools/converter.cxx
index d7adda1..1ed1d87 100644
--- a/sax/source/tools/converter.cxx
+++ b/sax/source/tools/converter.cxx
@@ -2035,10 +2035,11 @@ double Converter::GetConversionFactor(OUStringBuffer& rUnit, sal_Int16 nSourceUn
     double fRetval(1.0);
     rUnit.setLength(0L);
 
-    const sal_Char* psUnit = 0;
 
     if(nSourceUnit != nTargetUnit)
     {
+        const sal_Char* psUnit = 0;
+
         switch(nSourceUnit)
         {
             case MeasureUnit::TWIP:
diff --git a/sc/source/core/data/compressedarray.cxx b/sc/source/core/data/compressedarray.cxx
index 36249d2..6411fa8 100644
--- a/sc/source/core/data/compressedarray.cxx
+++ b/sc/source/core/data/compressedarray.cxx
@@ -89,7 +89,6 @@ size_t ScCompressedArray<A,D>::Search( A nAccess ) const
     long nLo    = 0;
     long nHi    = static_cast<long>(nCount) - 1;
     long nStart = 0;
-    long nEnd   = 0;
     long i      = 0;
     bool bFound = (nCount == 1);
     while (!bFound && nLo <= nHi)
@@ -99,7 +98,7 @@ size_t ScCompressedArray<A,D>::Search( A nAccess ) const
             nStart = static_cast<long>(pData[i - 1].nEnd);
         else
             nStart = -1;
-        nEnd = static_cast<long>(pData[i].nEnd);
+        long nEnd = static_cast<long>(pData[i].nEnd);
         if (nEnd < static_cast<long>(nAccess))
             nLo = ++i;
         else
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 3570386..e485885 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -425,7 +425,6 @@ void ScDocument::CreateValidTabNames(std::vector<OUString>& aNames, SCTAB nCount
     OUString aStrTable = rOpt.GetInitTabPrefix();
 
     OUStringBuffer rName;
-    bool         bOk   = false;
 
     // First test if the prefix is valid, if so only avoid doubles
     bool bPrefix = ValidTabName( aStrTable );
@@ -435,7 +434,7 @@ void ScDocument::CreateValidTabNames(std::vector<OUString>& aNames, SCTAB nCount
 
     for (SCTAB j = 0; j < nCount; ++j)
     {
-        bOk = false;
+        bool bOk = false;
         while(!bOk)
         {
             rName = aStrTable;
diff --git a/sc/source/core/data/dptabres.cxx b/sc/source/core/data/dptabres.cxx
index cda6832..7ccaa73 100644
--- a/sc/source/core/data/dptabres.cxx
+++ b/sc/source/core/data/dptabres.cxx
@@ -2756,10 +2756,9 @@ ScDPResultMember *ScDPResultDimension::FindMember(  SCROW  iData ) const
 
     unsigned int i;
     unsigned int nCount = maMemberArray.size();
-    ScDPResultMember* pResultMember;
     for( i = 0; i < nCount ; i++ )
     {
-        pResultMember = maMemberArray[i];
+        ScDPResultMember* pResultMember = maMemberArray[i];
         if ( pResultMember->IsNamedItem( iData ) )
             return pResultMember;
     }
@@ -4077,10 +4076,9 @@ void ScDPResultDimension::CheckShowEmpty( bool bShow )
 {
     long nCount = maMemberArray.size();
 
-    ScDPResultMember* pMember = NULL;
     for (long i=0; i<nCount; i++)
     {
-        pMember = maMemberArray.at(i);
+        ScDPResultMember* pMember = maMemberArray.at(i);
         pMember->CheckShowEmpty(bShow);
     }
 
diff --git a/sc/source/core/tool/addincol.cxx b/sc/source/core/tool/addincol.cxx
index 3dc1d49..48f060f 100644
--- a/sc/source/core/tool/addincol.cxx
+++ b/sc/source/core/tool/addincol.cxx
@@ -1568,8 +1568,7 @@ void ScUnoAddInCall::SetResult( const uno::Any& rNewRes )
                     long nRowCount = pRowSeq->getLength();
                     const uno::Sequence<sal_Int32>* pRowArr = pRowSeq->getConstArray();
                     long nMaxColCount = 0;
-                    long nCol, nRow;
-                    for (nRow=0; nRow<nRowCount; nRow++)
+                    for (long nRow=0; nRow<nRowCount; nRow++)
                     {
                         long nTmp = pRowArr[nRow].getLength();
                         if ( nTmp > nMaxColCount )
@@ -1580,15 +1579,15 @@ void ScUnoAddInCall::SetResult( const uno::Any& rNewRes )
                         xMatrix = new ScMatrix(
                                 static_cast<SCSIZE>(nMaxColCount),
                                 static_cast<SCSIZE>(nRowCount), 0.0);
-                        for (nRow=0; nRow<nRowCount; nRow++)
+                        for (long nRow=0; nRow<nRowCount; nRow++)
                         {
                             long nColCount = pRowArr[nRow].getLength();
                             const sal_Int32* pColArr = pRowArr[nRow].getConstArray();
-                            for (nCol=0; nCol<nColCount; nCol++)
+                            for (long nCol=0; nCol<nColCount; nCol++)
                                 xMatrix->PutDouble( pColArr[nCol],
                                         static_cast<SCSIZE>(nCol),
                                         static_cast<SCSIZE>(nRow) );
-                            for (nCol=nColCount; nCol<nMaxColCount; nCol++)
+                            for (long nCol=nColCount; nCol<nMaxColCount; nCol++)
                                 xMatrix->PutDouble( 0.0,
                                         static_cast<SCSIZE>(nCol),
                                         static_cast<SCSIZE>(nRow) );
@@ -1610,8 +1609,7 @@ void ScUnoAddInCall::SetResult( const uno::Any& rNewRes )
                     long nRowCount = pRowSeq->getLength();
                     const uno::Sequence<double>* pRowArr = pRowSeq->getConstArray();
                     long nMaxColCount = 0;
-                    long nCol, nRow;
-                    for (nRow=0; nRow<nRowCount; nRow++)
+                    for (long nRow=0; nRow<nRowCount; nRow++)
                     {
                         long nTmp = pRowArr[nRow].getLength();
                         if ( nTmp > nMaxColCount )
@@ -1622,15 +1620,15 @@ void ScUnoAddInCall::SetResult( const uno::Any& rNewRes )
                         xMatrix = new ScMatrix(
                                 static_cast<SCSIZE>(nMaxColCount),
                                 static_cast<SCSIZE>(nRowCount), 0.0);
-                        for (nRow=0; nRow<nRowCount; nRow++)
+                        for (long nRow=0; nRow<nRowCount; nRow++)
                         {
                             long nColCount = pRowArr[nRow].getLength();
                             const double* pColArr = pRowArr[nRow].getConstArray();
-                            for (nCol=0; nCol<nColCount; nCol++)
+                            for (long nCol=0; nCol<nColCount; nCol++)
                                 xMatrix->PutDouble( pColArr[nCol],
                                         static_cast<SCSIZE>(nCol),
                                         static_cast<SCSIZE>(nRow) );
-                            for (nCol=nColCount; nCol<nMaxColCount; nCol++)
+                            for (long nCol=nColCount; nCol<nMaxColCount; nCol++)
                                 xMatrix->PutDouble( 0.0,
                                         static_cast<SCSIZE>(nCol),
                                         static_cast<SCSIZE>(nRow) );
@@ -1652,8 +1650,7 @@ void ScUnoAddInCall::SetResult( const uno::Any& rNewRes )
                     long nRowCount = pRowSeq->getLength();
                     const uno::Sequence<OUString>* pRowArr = pRowSeq->getConstArray();
                     long nMaxColCount = 0;
-                    long nCol, nRow;
-                    for (nRow=0; nRow<nRowCount; nRow++)
+                    for (long nRow=0; nRow<nRowCount; nRow++)
                     {
                         long nTmp = pRowArr[nRow].getLength();
                         if ( nTmp > nMaxColCount )
@@ -1664,17 +1661,17 @@ void ScUnoAddInCall::SetResult( const uno::Any& rNewRes )
                         xMatrix = new ScMatrix(
                                 static_cast<SCSIZE>(nMaxColCount),
                                 static_cast<SCSIZE>(nRowCount), 0.0);
-                        for (nRow=0; nRow<nRowCount; nRow++)
+                        for (long nRow=0; nRow<nRowCount; nRow++)
                         {
                             long nColCount = pRowArr[nRow].getLength();
                             const OUString* pColArr = pRowArr[nRow].getConstArray();
-                            for (nCol=0; nCol<nColCount; nCol++)
+                            for (long nCol=0; nCol<nColCount; nCol++)
                             {
                                 xMatrix->PutString(
                                     svl::SharedString(pColArr[nCol]),
                                     static_cast<SCSIZE>(nCol), static_cast<SCSIZE>(nRow));
                             }
-                            for (nCol=nColCount; nCol<nMaxColCount; nCol++)
+                            for (long nCol=nColCount; nCol<nMaxColCount; nCol++)
                             {
                                 xMatrix->PutString(
                                     svl::SharedString(EMPTY_OUSTRING),
diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index ce59e26..b596d42 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -6826,7 +6826,6 @@ void ScInterpreter::DBIterator( ScIterFunc eFunc )
 {
     double nErg = 0.0;
     double fMem = 0.0;
-    bool bNull = true;
     sal_uLong nCount = 0;
     bool bMissingField = false;
     unique_ptr<ScDBQueryParamBase> pQueryParam( GetDBParams(bMissingField) );
@@ -6848,6 +6847,8 @@ void ScInterpreter::DBIterator( ScIterFunc eFunc )
                 case ifMIN:     nErg = MAXDOUBLE; break;
                 default: ; // nothing
             }
+
+            bool bNull = true;
             do
             {
                 nCount++;


More information about the Libreoffice-commits mailing list