Skip to content

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

Merged
merged 3 commits into from
Nov 12, 2024

Conversation

jketema
Copy link
Contributor

@jketema jketema commented Nov 11, 2024

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

Internal query authors only

  • Autofixes generated based on these changes are valid, only needed if this PR makes significant changes to .ql, .qll, or .qhelp files. See the documentation (internal access required).
  • Changes are validated at scale (internal access required).
  • Adding a new query? Consider also adding the query to autofix.

@jketema jketema requested a review from a team as a code owner November 11, 2024 16:31
@github-actions github-actions bot added the C++ label Nov 11, 2024

void test14(char *x) {
if(x != nullptr) // GOOD [FALSE POSITIVE]: x might be accessed
inspect(x), free(x);
Copy link
Contributor

@paldepind paldepind Nov 12, 2024

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?

Copy link
Contributor Author

@jketema jketema Nov 12, 2024

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.

Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

@paldepind paldepind left a 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 😄

@jketema jketema merged commit 77ae26f into github:main Nov 12, 2024
10 checks passed
@jketema jketema deleted the guarded-free branch November 12, 2024 09:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants