-
Notifications
You must be signed in to change notification settings - Fork 1.8k
C++: Add tests for experimental cpp/guarded-free
query
#17960
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
Conversation
cpp/ql/test/experimental/query-tests/Best Practices/GuardedFree/test.cpp
Outdated
Show resolved
Hide resolved
cpp/ql/test/experimental/query-tests/Best Practices/GuardedFree/test.cpp
Outdated
Show resolved
Hide resolved
cpp/ql/test/experimental/query-tests/Best Practices/GuardedFree/test.cpp
Outdated
Show resolved
Hide resolved
|
||
void test14(char *x) { | ||
if(x != nullptr) // GOOD [FALSE POSITIVE]: x might be accessed | ||
inspect(x), free(x); |
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.
Is the comma operator what's causing the issue? Or does this also fail with { inspect(x); free(x); }
? If it does then maybe just use semicolons? If not, would it make sense to add a comment to clarify that?
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.
The problem is that inspect
may assume that x
is non-null, so if the remove the if
, which is what the query is about, the thing would start crashing. Note that this derives from code I saw in the wild. Replacing it by { inspect(x); free(x); }
would not give an FP.
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.
Then what about changing the comment to:
// GOOD [FALSE POSITIVE]: x might be accessed in the first operand of the comma operator
Or something else to make it clear that ,
is part of the problem/what is being tested?
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.
Done.
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.
Looks good. Just a few comments 😄
I investigated a bit if the query can be promoted (instead of moving it to a separate repo). The tests highlight some issues.
Pull Request checklist
All query authors
.qhelp
. See the documentation in this repository.Internal query authors only
.ql
,.qll
, or.qhelp
files. See the documentation (internal access required).