-
Notifications
You must be signed in to change notification settings - Fork 362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce the variable scope, if possible #173
Open
gunterkoenigsmann
wants to merge
1
commit into
memononen:master
Choose a base branch
from
gunterkoenigsmann:variableScope
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Reduce the variable scope, if possible #173
gunterkoenigsmann
wants to merge
1
commit into
memononen:master
from
gunterkoenigsmann:variableScope
Conversation
This file contains 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
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
@@ -1296,18 +1299,19 @@ static void nsvg__initPaint(NSVGcachedPaint* cache, NSVGpaint* paint, float opac | |||
for (i = 0; i < ia; i++) { | |||
cache->colors[i] = ca; | |||
} | |||
|
|||
There was a problem hiding this comment.
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
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: