Reduce the variable scope, if possible#173
Open
gunterkoenigsmann wants to merge 1 commit intomemononen:masterfrom
Open
Reduce the variable scope, if possible#173gunterkoenigsmann wants to merge 1 commit intomemononen:masterfrom
gunterkoenigsmann wants to merge 1 commit intomemononen:masterfrom
Conversation
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;
^
tesch1
reviewed
Dec 25, 2019
| cache->colors[i] = ca; | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: