Skip to content

Conversation

gunterkoenigsmann
Copy link

CppCheck complains if a variable definition can be moved into one block without changing the outcome. The rationale is that defining the variable outside the block often hints to the variable's value persisting throughout a while or for loop. Also if defined outside a block it occupies stack space longer than necessary. ⇒ Reduced the scope of all variables, wherever possible which causes the following cppcheck warnings to disappear:

nanosvgrast.h:1024:21: warning: The scope of the variable 'gy' can be reduced. [variableScope]
  float fx, fy, dx, gy;
                    ^
nanosvgrast.h:1026:10: warning: The scope of the variable 'cr' can be reduced. [variableScope]
  int i, cr, cg, cb, ca;
         ^
nanosvgrast.h:1026:14: warning: The scope of the variable 'cg' can be reduced. [variableScope]
  int i, cr, cg, cb, ca;
             ^
nanosvgrast.h:1026:18: warning: The scope of the variable 'cb' can be reduced. [variableScope]
  int i, cr, cg, cb, ca;
                 ^
nanosvgrast.h:1026:22: warning: The scope of the variable 'ca' can be reduced. [variableScope]
  int i, cr, cg, cb, ca;
                     ^
nanosvgrast.h:1027:16: warning: The scope of the variable 'c' can be reduced. [variableScope]
  unsigned int c;
               ^
nanosvgrast.h:1069:21: warning: The scope of the variable 'gx' can be reduced. [variableScope]
  float fx, fy, dx, gx, gy, gd;
                    ^
nanosvgrast.h:1069:25: warning: The scope of the variable 'gy' can be reduced. [variableScope]
  float fx, fy, dx, gx, gy, gd;
                        ^
nanosvgrast.h:1069:29: warning: The scope of the variable 'gd' can be reduced. [variableScope]
  float fx, fy, dx, gx, gy, gd;
                            ^
nanosvgrast.h:1071:10: warning: The scope of the variable 'cr' can be reduced. [variableScope]
  int i, cr, cg, cb, ca;
         ^
nanosvgrast.h:1071:14: warning: The scope of the variable 'cg' can be reduced. [variableScope]
  int i, cr, cg, cb, ca;
             ^
nanosvgrast.h:1071:18: warning: The scope of the variable 'cb' can be reduced. [variableScope]
  int i, cr, cg, cb, ca;
                 ^
nanosvgrast.h:1071:22: warning: The scope of the variable 'ca' can be reduced. [variableScope]
  int i, cr, cg, cb, ca;
                     ^
nanosvgrast.h:1072:16: warning: The scope of the variable 'c' can be reduced. [variableScope]
  unsigned int c;
               ^
nanosvgrast.h:1225:8: warning: The scope of the variable 'r' can be reduced. [variableScope]
   int r = 0, g = 0, b = 0, a = row[3], n = 0;
       ^
nanosvgrast.h:1225:15: warning: The scope of the variable 'g' can be reduced. [variableScope]
   int r = 0, g = 0, b = 0, a = row[3], n = 0;
              ^
nanosvgrast.h:1225:22: warning: The scope of the variable 'b' can be reduced. [variableScope]
   int r = 0, g = 0, b = 0, a = row[3], n = 0;
                     ^
nanosvgrast.h:1225:41: warning: The scope of the variable 'n' can be reduced. [variableScope]
   int r = 0, g = 0, b = 0, a = row[3], n = 0;
                                        ^
nanosvgrast.h:1265:9: warning: The scope of the variable 'j' can be reduced. [variableScope]
 int i, j;
        ^
nanosvgrast.h:1289:15: warning: The scope of the variable 'count' can be reduced. [variableScope]
  int ia, ib, count;
              ^

CppCheck complains if a variable definition can be moved into
one block without changing the outcome. The rationale is that
defining the variable outside the block often hints to the
variable's value persisting throughout a while or for loop.
Also if defined outside a block it occupies stack space
longer than necessary. => Reduced the scope of all variables,
wherever possible which causes the following cppcheck warnings
to disappear:

nanosvgrast.h:1024:21: warning: The scope of the variable 'gy' can be reduced. [variableScope]
  float fx, fy, dx, gy;
                    ^
nanosvgrast.h:1026:10: warning: The scope of the variable 'cr' can be reduced. [variableScope]
  int i, cr, cg, cb, ca;
         ^
nanosvgrast.h:1026:14: warning: The scope of the variable 'cg' can be reduced. [variableScope]
  int i, cr, cg, cb, ca;
             ^
nanosvgrast.h:1026:18: warning: The scope of the variable 'cb' can be reduced. [variableScope]
  int i, cr, cg, cb, ca;
                 ^
nanosvgrast.h:1026:22: warning: The scope of the variable 'ca' can be reduced. [variableScope]
  int i, cr, cg, cb, ca;
                     ^
nanosvgrast.h:1027:16: warning: The scope of the variable 'c' can be reduced. [variableScope]
  unsigned int c;
               ^
nanosvgrast.h:1069:21: warning: The scope of the variable 'gx' can be reduced. [variableScope]
  float fx, fy, dx, gx, gy, gd;
                    ^
nanosvgrast.h:1069:25: warning: The scope of the variable 'gy' can be reduced. [variableScope]
  float fx, fy, dx, gx, gy, gd;
                        ^
nanosvgrast.h:1069:29: warning: The scope of the variable 'gd' can be reduced. [variableScope]
  float fx, fy, dx, gx, gy, gd;
                            ^
nanosvgrast.h:1071:10: warning: The scope of the variable 'cr' can be reduced. [variableScope]
  int i, cr, cg, cb, ca;
         ^
nanosvgrast.h:1071:14: warning: The scope of the variable 'cg' can be reduced. [variableScope]
  int i, cr, cg, cb, ca;
             ^
nanosvgrast.h:1071:18: warning: The scope of the variable 'cb' can be reduced. [variableScope]
  int i, cr, cg, cb, ca;
                 ^
nanosvgrast.h:1071:22: warning: The scope of the variable 'ca' can be reduced. [variableScope]
  int i, cr, cg, cb, ca;
                     ^
nanosvgrast.h:1072:16: warning: The scope of the variable 'c' can be reduced. [variableScope]
  unsigned int c;
               ^
nanosvgrast.h:1225:8: warning: The scope of the variable 'r' can be reduced. [variableScope]
   int r = 0, g = 0, b = 0, a = row[3], n = 0;
       ^
nanosvgrast.h:1225:15: warning: The scope of the variable 'g' can be reduced. [variableScope]
   int r = 0, g = 0, b = 0, a = row[3], n = 0;
              ^
nanosvgrast.h:1225:22: warning: The scope of the variable 'b' can be reduced. [variableScope]
   int r = 0, g = 0, b = 0, a = row[3], n = 0;
                     ^
nanosvgrast.h:1225:41: warning: The scope of the variable 'n' can be reduced. [variableScope]
   int r = 0, g = 0, b = 0, a = row[3], n = 0;
                                        ^
nanosvgrast.h:1265:9: warning: The scope of the variable 'j' can be reduced. [variableScope]
 int i, j;
        ^
nanosvgrast.h:1289:15: warning: The scope of the variable 'count' can be reduced. [variableScope]
  int ia, ib, count;
              ^
cache->colors[i] = ca;
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants