OSDN Git Service

Cppcheck: The scope of the variable '...' can be reduced
authorTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sat, 23 Mar 2019 06:12:10 +0000 (15:12 +0900)
committerTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sat, 23 Mar 2019 06:12:10 +0000 (15:12 +0900)
Externals/crystaledit/editlib/batch.cpp
Externals/crystaledit/editlib/ccrystaltextbuffer.cpp
Externals/crystaledit/editlib/ccrystaltextview.cpp
Externals/crystaledit/editlib/filesup.cpp
Externals/crystaledit/editlib/fpattern.cpp
Externals/crystaledit/editlib/string_util.cpp
Externals/crystaledit/editlib/wcwidth.cpp
Src/Common/LanguageSelect.cpp

index 09aab11..61a0dce 100644 (file)
@@ -654,15 +654,14 @@ IsBatKeyword (LPCTSTR pszChars, int nLength)
 static bool
 IsUser1Keyword (LPCTSTR pszChars, int nLength)
 {
-  const int bufsiz = 13;
-  TCHAR buffer[bufsiz];
-
   if (nLength < 4 || pszChars[nLength - 4] != '.')
     {
       return ISXKEYWORDI(s_apszUser1KeywordList, pszChars, (size_t)nLength);
     }
   else
     {
+      const int bufsiz = 13;
+      TCHAR buffer[bufsiz];
       for (int L = 0; L < sizeof(s_apszUser1KeywordList)/sizeof(TCHAR *); L++)
         {
           _tcscpy_s (buffer, bufsiz, s_apszUser1KeywordList[L]);
index b56fe6f..90f9215 100644 (file)
@@ -1132,11 +1132,10 @@ InternalInsertText (CCrystalTextView * pSource, int nLine, int nPos,
 
   int nInsertedLines = 0;
   int nCurrentLine = nLine;
-  size_t nTextPos;
   for (;;)
     {
       int haseol = 0;
-      nTextPos = 0;
+      size_t nTextPos = 0;
       // advance to end of line
       while (nTextPos < cchText && !LineInfo::IsEol(pszText[nTextPos]))
         nTextPos++;
index 1b934ab..a668d2f 100644 (file)
@@ -1923,14 +1923,12 @@ GetHTMLStyles ()
   };
 
   CString strStyles;
-  int nColorIndex, nBgColorIndex;
-  int f, b;
-  for (f = 0; f < sizeof(arColorIndices)/sizeof(int); f++)
+  for (int f = 0; f < sizeof(arColorIndices)/sizeof(int); f++)
     {
-      nColorIndex = arColorIndices[f];
-      for (b = 0; b < sizeof(arBgColorIndices)/sizeof(int); b++)
+      int nColorIndex = arColorIndices[f];
+      for (int b = 0; b < sizeof(arBgColorIndices)/sizeof(int); b++)
         {
-          nBgColorIndex = arBgColorIndices[b];
+          int nBgColorIndex = arBgColorIndices[b];
           COLORREF clr;
 
           strStyles += Fmt (_T(".sf%db%d {"), nColorIndex, nBgColorIndex);
@@ -5046,11 +5044,11 @@ FindTextInBlock (LPCTSTR pszText, const CPoint & ptStartPosition,
         {
           while (ptCurrentPos.y <= ptBlockEnd.y)
             {
-              int nLineLength, nLines;
+              int nLineLength;
               CString line;
               if (dwFlags & FIND_REGEXP)
                 {
-                  nLines = m_pTextBuffer->GetLineCount ();
+                  int nLines = m_pTextBuffer->GetLineCount ();
                   for (int i = 0; i <= nEolns && ptCurrentPos.y + i < nLines; i++)
                     {
                       CString item;
index 845e187..b99df57 100644 (file)
@@ -74,9 +74,9 @@ int GetNamePosition (LPCTSTR pszString)
     return 0;
   const CString sString = pszString;
   int posit = sString.GetLength ();
-  TCHAR test;
   do
   {
+    TCHAR test;
 #ifdef _UNICODE
     if ((test = sString.GetAt (--posit)) == _T ('\\') || test == _T (':'))
 #else
index 2518858..038e8f8 100644 (file)
@@ -141,8 +141,6 @@ fpattern_isvalid (LPCTSTR pat)
 static int
 fpattern_submatch (LPCTSTR pat, LPCTSTR fname)
 {
-  TCHAR fch;
-  TCHAR pch;
   int i;
   bool yes, match;
   TCHAR lo, hi;
@@ -150,8 +148,8 @@ fpattern_submatch (LPCTSTR pat, LPCTSTR fname)
   /* Attempt to match subpattern against subfilename */
   while (*pat != _T('\0'))
     {
-      fch = *fname;
-      pch = *pat;
+      TCHAR fch = *fname;
+      TCHAR pch = *pat;
       pat++;
 
       switch (pch)
index 5dce1f5..27b4b23 100644 (file)
@@ -64,12 +64,10 @@ bool IsXKeyword(LPCTSTR pszKey, size_t nKeyLen, LPCTSTR pszKeywordList[], size_t
 {
        TCHAR **base = (TCHAR **)pszKeywordList;
        size_t lim;
-       int cmp;
-       TCHAR **p;
 
        for (lim = nKeywordListCount; lim != 0; lim >>= 1) {
-               p = base + (lim >> 1) ;
-               cmp = (*compare)(pszKey, *p, nKeyLen);
+               TCHAR **p = base + (lim >> 1) ;
+               int cmp = (*compare)(pszKey, *p, nKeyLen);
                if (cmp == 0 && (*p)[nKeyLen] == 0)
                        return true;
                if (cmp > 0) {  /* key > p: move right */
index bfa67ac..8ddfb82 100644 (file)
@@ -70,12 +70,11 @@ struct interval {
 /* auxiliary function for binary search in interval table */
 static int bisearch(wchar_t ucs, const struct interval *table, int max) {
   int min = 0;
-  int mid;
 
   if (ucs < table[0].first || ucs > table[max].last)
     return 0;
   while (max >= min) {
-    mid = (min + max) / 2;
+    int mid = (min + max) / 2;
     if (ucs > table[mid].last)
       min = mid + 1;
     else if (ucs < table[mid].first)
index 3a0fe56..f0309c8 100644 (file)
@@ -577,7 +577,6 @@ bool CLanguageSelect::LoadLanguageFile(LANGID wLangId, bool bShowError /*= false
        wchar_t buf[1024];
        std::wstring *ps = nullptr;
        std::wstring msgid;
-       unsigned uid = 0;
        bool found_uid = false;
        FILE *f;
        if (_tfopen_s(&f, strPath.c_str(), _T("r,ccs=UTF-8")) != 0)
@@ -601,7 +600,6 @@ bool CLanguageSelect::LoadLanguageFile(LANGID wLangId, bool bShowError /*= false
                {
                        if (wchar_t *q = wcschr(p0, ':'))
                        {
-                               uid = wcstoul(q + 1, &q, 16);
                                found_uid = true;
                        }
                }