CPP: Add query for CWE-1126: Declaration of Variable with Unnecessarily Wide Scope#5767
CPP: Add query for CWE-1126: Declaration of Variable with Unnecessarily Wide Scope#5767geoffw0 merged 11 commits intogithub:mainfrom ihsinme:ihsinme-patch-268
Conversation
geoffw0
left a comment
There was a problem hiding this comment.
This reminds me of the queries in Best Practices/Hiding, especially cpp/declaration-hides-variable. Your query appears to be a more specialized version looking for instances where there's evidence the hiding is causing a real problem.
…iableWithUnnecessarilyWideScope.c Co-authored-by: Geoffrey White <40627776+geoffw0@users.noreply.github.com>
|
thanks for your comments. |
|
Started a test run on LGTM: https://lgtm.com/query/3978555328191505856/ |
good day. |
|
thanks for the note with recursion. |
|
I've reported the comment two up, I think it might be some kind of spam. I suggest we ignore it and continue working on the query... |
geoffw0
left a comment
There was a problem hiding this comment.
I think you've addressed all of the suggestions, the QL is satisfactory and the tests are excellent.
Results on LGTM: https://lgtm.com/query/8106651676569760712/ (very few, probably because we're looking for cases that are definitely causing problems rather than just any instances of reusing variable names).
Good day.
in this request I am looking at the error of using a new variable inside a loop.
in a situation where a variable with the same name participates in a loop condition.
the most dangerous situation is the while loop in the absence of changes to the variables participating in the condition.
At this stage, I tried to minimize false positives as much as possible.
I left the situation of changing a variable through a function call. as I considered it a rather rare practice. if you disagree with me, I will listen to you
current PR.
sleuthkit/sleuthkit#2329