C++: Fix queries after shared guards#958
Merged
jketema merged 1 commit intogithub:nextfrom Oct 2, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes compatibility issues in C++ queries following the migration from a C/C++-specific guards library to a shared guards library. The key change is that GuardCondition is now an Element instead of always being an Expr, requiring explicit casts in several queries.
- Adds explicit casts to
Exprwhen accessing children ofGuardConditionobjects - Updates class inheritance to use
instanceof Exprconstraint forGuardCondition - Maintains existing functionality while ensuring type safety after the guards library migration
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| FunctionErroneousReturnValueNotTested.qll | Adds explicit cast to Expr when accessing children of GuardCondition |
| DetectAndHandleMemoryAllocationErrors.ql | Adds explicit cast to Expr when accessing children of GuardCondition |
| DoNotUseAnAdditiveOperatorOnAnIterator.ql | Adds explicit casts to Expr for GuardCondition child access in multiple locations |
| DoNotCompareFunctionPointersToConstantValues.ql | Updates class inheritance to constrain GuardCondition to instanceof Expr |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
jketema
approved these changes
Oct 2, 2025
30 tasks
This file contains hidden or 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
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.
Description
github/codeql#20485 switches C/C++ away from its own guards library and over to the shared guards library (which is currently used by Java, and soon by C#). One of the changes is that a
GuardConditionis now anElementinstead of always being anExpr. So a couple of the coding standard queries needs an additional cast.Change request type
.ql,.qll,.qlsor unit tests)Rules with added or modified queries
Release change checklist
A change note (development_handbook.md#change-notes) is required for any pull request which modifies:
If you are only adding new rule queries, a change note is not required.
Author: Is a change note required?
🚨🚨🚨
Reviewer: Confirm that format of shared queries (not the .qll file, the
.ql file that imports it) is valid by running them within VS Code.
Reviewer: Confirm that either a change note is not required or the change note is required and has been added.
Query development review checklist
For PRs that add new queries or modify existing queries, the following checklist should be completed by both the author and reviewer:
Author
As a rule of thumb, predicates specific to the query should take no more than 1 minute, and for simple queries be under 10 seconds. If this is not the case, this should be highlighted and agreed in the code review process.
Reviewer
As a rule of thumb, predicates specific to the query should take no more than 1 minute, and for simple queries be under 10 seconds. If this is not the case, this should be highlighted and agreed in the code review process.