Skip to content
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

Fix variable scope warnings #190

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

ercanersoy
Copy link

Fixed variable scope warnings on jsmn.h, test/testc.c and test/testutil.h files.

These warnings have been founded by using Cppcheck 1.86.

This warning has been founded by using Cppcheck 1.86.

Signed-off-by: Ercan Ersoy <ercanersoy@ercanersoy.net>
These warnings have been founded by using Cppcheck 1.86.

Signed-off-by: Ercan Ersoy <ercanersoy@ercanersoy.net>
Signed-off-by: Ercan Ersoy <ercanersoy@ercanersoy.net>
@pt300
Copy link
Collaborator

pt300 commented Apr 8, 2020

Breaks C89 compatibility.

@pt300
Copy link
Collaborator

pt300 commented Apr 8, 2020

Some of those changes might make sense but I don't really see them as necessary.

- Deleted unconditional integer variable definition on for loop. It is
  unneeded except JSMN_PARENT_LINKS option.
- Added conditional integer variable definition before for loop.

Signed-off-by: Ercan Ersoy <ercanersoy@ercanersoy.net>
@ercanersoy
Copy link
Author

Variable scope warnings can reduce optimizations.

@pt300
Copy link
Collaborator

pt300 commented Apr 8, 2020

I don't see the point of those optimizations in the tests and doubt that the single redeclaration will matter on platforms targeted by JSMN.

@ercanersoy
Copy link
Author

Cppcheck results of jsmn.h on your repository:

jsmn.h:271:7: warning: The scope of the variable 'i' can be reduced. [variableScope]

I have used Cppcheck 1.86. I have used this command line:

cppcheck --language=c --std=c89 --enable=all --template=gcc "jsmn.h"

Reference:

https://stackoverflow.com/questions/23604699/cppcheck-the-scope-of-the-variable-can-be-reduced-and-loop

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