OSDN Git Service

Cppcheck: The scope of the variable '...' can be reduced.
authorsdottaka <sdottaka@users.sourceforge.net>
Sat, 18 Jul 2015 02:17:37 +0000 (11:17 +0900)
committersdottaka <sdottaka@users.sourceforge.net>
Sat, 18 Jul 2015 02:17:37 +0000 (11:17 +0900)
--HG--
branch : stable

Src/Common/ExConverter.cpp
Src/Common/lwdisp.c
Src/Diff3.h
Src/DiffList.cpp
Src/GhostTextBuffer.cpp
Src/LineFiltersList.cpp
Src/PatchHTML.cpp
Src/SourceControl.cpp
Src/VSSHelper.cpp
Src/markdown.cpp

index f56c887..7314e85 100644 (file)
@@ -197,7 +197,7 @@ public:
                                        {
                                                bezerocount++;
                                                if (data[i + 1] == 0x0a || data[i + 1] == 0x0d)
-                                                       lecrorlf++;
+                                                       becrorlf++;
                                        }
                                        else if (data[i + 1] == 0)
                                        {
index 3d5d8d6..b782052 100644 (file)
@@ -360,7 +360,6 @@ STDAPI invokeV(LPDISPATCH pi, VARIANT *ret, DISPID id, LPCCH op, VARIANT *argv)
        DISPPARAMS dispparams;
        UINT nArgErr = (UINT)-1;
        EXCEPINFO excepInfo = {0};
-       int i;
        dispparams.cArgs = LOBYTE((UINT_PTR)op);
        dispparams.cNamedArgs = 0;
        if (wFlags & (DISPATCH_PROPERTYPUT|DISPATCH_PROPERTYPUTREF))
@@ -375,7 +374,7 @@ STDAPI invokeV(LPDISPATCH pi, VARIANT *ret, DISPID id, LPCCH op, VARIANT *argv)
                VARIANT varParams[12];
                VARIANT varData[12];
 
-               for (i = 0; i < (int)dispparams.cArgs; i++)
+               for (int i = 0; i < (int)dispparams.cArgs; i++)
                {
                        if (V_ISBYREF(&argv[i]))
                        {
@@ -414,7 +413,7 @@ STDAPI invokeV(LPDISPATCH pi, VARIANT *ret, DISPID id, LPCCH op, VARIANT *argv)
 
                if (bNeedToConv)
                {
-                       for (i = 0; i < (int)dispparams.cArgs; i++)
+                       for (int i = 0; i < (int)dispparams.cArgs; i++)
                        {
                                VariantInit(&varData[i]);
                                VariantCopyInd(&varData[i], &argv[i]);
@@ -452,7 +451,7 @@ STDAPI invokeV(LPDISPATCH pi, VARIANT *ret, DISPID id, LPCCH op, VARIANT *argv)
                {
                        if (bNeedToConv)
                        {
-                               for (i = 0; i < (int)dispparams.cArgs; i++)
+                               for (int i = 0; i < (int)dispparams.cArgs; i++)
                                {
                                        if (V_ISBYREF(&argv[i]))
                                        {
index 1cf13c6..8101542 100644 (file)
@@ -21,13 +21,9 @@ size_t Make3wayDiff(std::vector<Element>& diff3, const std::vector<Element>& dif
        size_t diff12i = 0;
        size_t diff3i = 0;
 
-       size_t diff10itmp;
-       size_t diff12itmp;
-
-       bool lastDiffBlockIsDiff12;
        bool firstDiffBlockIsDiff12;
 
-       Element dr3, dr10, dr12, dr10first, dr10last, dr12first, dr12last;
+               Element dr3, dr10, dr12, dr10first, dr10last, dr12first, dr12last;
 
        int linelast0 = 0;
        int linelast1 = 0;
@@ -78,10 +74,10 @@ size_t Make3wayDiff(std::vector<Element>& diff3, const std::vector<Element>& dif
                        else
                                firstDiffBlockIsDiff12 = false;
                }
-               lastDiffBlockIsDiff12 = firstDiffBlockIsDiff12;
+               bool lastDiffBlockIsDiff12 = firstDiffBlockIsDiff12;
 
-               diff10itmp = diff10i;
-               diff12itmp = diff12i;
+               size_t diff10itmp = diff10i;
+               size_t diff12itmp = diff12i;
                for (;;)
                {
                        if (diff10itmp >= diff10count || diff12itmp >= diff12count)
index 995d902..d23ea8c 100644 (file)
@@ -291,12 +291,11 @@ int DiffList::LineToDiff(int nLine) const
 
        // Use binary search to search for a diff.
        int left = 0; // Left limit
-       int middle = 0; // Compared item
        int right = nDiffCount - 1; // Right limit
 
        while (left <= right)
        {
-               middle = (left + right) / 2;
+               int middle = (left + right) / 2; // Compared item
                int result = LineRelDiff(nLine, middle);
                switch (result)
                {
index f83de26..1849636 100644 (file)
@@ -964,10 +964,9 @@ int CGhostTextBuffer::ComputeRealLine(int nApparentLine) const
        // binary search to find correct (or nearest block)
        int blo = 0;
        int bhi = size - 1;
-       int i;
        while (blo <= bhi)
        {
-               i = (blo + bhi) / 2;
+               int i = (blo + bhi) / 2;
                const RealityBlock &block = m_RealityBlocks[i];
                if (nApparentLine < block.nStartApparent)
                        bhi = i - 1;
@@ -1000,10 +999,9 @@ int CGhostTextBuffer::ComputeApparentLine(int nRealLine) const
        // binary search to find correct (or nearest block)
        int blo = 0;
        int bhi = size - 1;
-       int i;
        while (blo <= bhi)
        {
-               i = (blo + bhi) / 2;
+               int i = (blo + bhi) / 2;
                const RealityBlock & block = m_RealityBlocks[i];
                if (nRealLine < block.nStartReal)
                        bhi = i - 1;
@@ -1051,10 +1049,9 @@ int CGhostTextBuffer::ComputeRealLineAndGhostAdjustment(int nApparentLine,
        // binary search to find correct (or nearest block)
        int blo = 0;
        int bhi = size - 1;
-       int i;
        while (blo <= bhi)
        {
-               i = (blo + bhi) / 2;
+               int i = (blo + bhi) / 2;
                const RealityBlock & block = m_RealityBlocks[i];
                if (nApparentLine < block.nStartApparent)
                        bhi = i - 1;
index 18c9134..c61ebd6 100644 (file)
@@ -228,12 +228,11 @@ void LineFiltersList::Import(const String& filters)
 {
        const TCHAR sep[] = _T("\r\n");
        TCHAR *p_filters = (TCHAR *)&filters[0];
-       TCHAR *token;
        
        if (!filters.empty())
        {
                // find each regular expression and add to list
-               token = _tcstok(p_filters, sep);
+               TCHAR *token = _tcstok(p_filters, sep);
                while (token)
                {
                        AddFilter(token, true);
index aa33f3c..27c0419 100644 (file)
@@ -330,14 +330,14 @@ static struct change *
 find_hunk (struct change *start)
 {
   struct change *prev;
-  int top0, top1;
+  int top0;
   int thresh;
 
   do
     {
       /* Compute number of first line in each file beyond this changed.  */
       top0 = start->line0 + start->deleted;
-      top1 = start->line1 + start->inserted;
+      int top1 = start->line1 + start->inserted;
       prev = start;
       start = start->link;
       /* Threshold distance is 2*CONTEXT between two non-ignorable changes,
@@ -395,13 +395,12 @@ static void
 output_1_escapedhtml(const char *text, const char *limit)
 {
   FILE *out = outfile;
-  unsigned char c;
   const char *t = text;
   int column = 0;
   int spcolumn = -2;
 
   while (t < limit)
-    switch ((c = *t++))
+    switch (unsigned char c = *t++)
       {
       case '&':
        fprintf (out, "&amp;");
index 9309ee0..f7347a2 100644 (file)
@@ -386,7 +386,6 @@ void CMergeApp::CheckinToClearCase(const String &strDestinationPath)
 {
        String spath, sname;
        paths_SplitFilename(strDestinationPath, &spath, &sname, 0);
-       int code;
        std::vector<std::string> args;
        std::string sname_utf8;
        
@@ -399,7 +398,7 @@ void CMergeApp::CheckinToClearCase(const String &strDestinationPath)
        try
        {
                ProcessHandle hVss(Process::launch(vssPath, args));
-               code = Process::wait(hVss);
+               int code = Process::wait(hVss);
                if (code != 0)
                {
                        if (LangMessageBox(IDS_VSS_CHECKINERROR, MB_ICONWARNING | MB_YESNO) == IDYES)
index e7f0114..e9f28f3 100644 (file)
@@ -56,8 +56,6 @@ bool VSSHelper::SetProjectBase(const String& strPath)
 bool VSSHelper::ReLinkVCProj(const String& strSavePath, String& sError)
 {
        const UINT nBufferSize = 1024;
-       TCHAR buffer[nBufferSize] = {0};
-       bool bVCPROJ = false;
 
        String tempFile = env_GetTempFileName(env_GetTempPath(), _T("_LT"));
        if (tempFile.empty())
@@ -71,6 +69,7 @@ bool VSSHelper::ReLinkVCProj(const String& strSavePath, String& sError)
        String strExt = string_makelower(ext);
        if (strExt == _T("vcproj") || strExt == _T("sln"))
        {
+               bool bVCPROJ = false;
                GetFullVSSPath(strSavePath, bVCPROJ);
 
                HANDLE hfile;
@@ -114,6 +113,7 @@ bool VSSHelper::ReLinkVCProj(const String& strSavePath, String& sError)
                }
 
                static TCHAR charset[] = _T(" \t\n\r=");
+               TCHAR buffer[nBufferSize] = {0};
                DWORD numwritten = 0;
                bool succeed = true;
        
@@ -399,7 +399,6 @@ bool VSSHelper::GetSLNProjUniqueName(HANDLE hFile, HANDLE tFile, TCHAR * buf) co
 
 bool VSSHelper::GetSLNProjName(HANDLE hFile, HANDLE tFile, TCHAR * buf) const
 {
-       TCHAR buffer[1024] = {0};
        DWORD dwNumWritten = 0;
 
        assert(hFile != NULL && hFile != INVALID_HANDLE_VALUE &&
@@ -409,6 +408,8 @@ bool VSSHelper::GetSLNProjName(HANDLE hFile, HANDLE tFile, TCHAR * buf) const
        String capp;
        if (*buf != '\\' && !_tcsstr(buf, _T(".")))
        {
+               TCHAR buffer[1024] = {0};
+
                //write out \\u0020s for every space in buffer2
                for (TCHAR * pc = buf; *pc; pc++)
                {
index 28ec236..28b89e6 100644 (file)
@@ -511,7 +511,6 @@ std::string CMarkdown::GetTagName() const
 {
        const char *p = first;
        const char *q = first;
-       unsigned char c;
        if (q < ahead && (p = ++q) < ahead)
        {
                if (*q == '!' && (*++q == '-' || *q == '['))
@@ -520,6 +519,7 @@ std::string CMarkdown::GetTagName() const
                }
                else
                {
+                       unsigned char c;
                        while (q < ahead && !isspace(c = *q) && c != '[' && c != '>' && c != '"' && c != '\'' && c != '=' && c != '/')
                        {
                                ++q;