- Notifications
You must be signed in to change notification settings - Fork69
Add "Baseline" query suites for C/C++.#966
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
These are queries from MISRA, AUTOSAR, and CERT, that have been hand pickedbased on a few properties:- review of violation count for each rule on real projects- review of accuracy of each rule- subjective review of broad applicability across most projects- subjective review of severity of each ruleThe baseline rules have been divided into two categories, "style," and "safety."The choice of which is subjective, but as a general rule:- Rules that tend to report only erroneous cases are typically "safety."- Rules that tend to report patterns that obscure erroneous behavior are typically "style."- If alerts can be mitigated by simple changes, it's more likely "style."- If it is challenging for a human to spot the rule violation, it's more likely "safety."- If the rule is designed to enforce some kind of "good habits," not just fix an isolated it's more likely "style."- If the rule feels "opinionated" in some sense, it's more likely "style."- If it is difficult to decide whether a finding should be fixed or deviated, it is more likely "safety."- Unsurprisingly, if the rule is purely syntactic or related to naming, it's more likely "style."Some rules are in both suites -- for instance, rules that ban the use of 'goto'are conceivably both "style" and "safety." While goto is not erroneous initself, and gotos are easy to spot during human review, it is typically not asimple task to refactor code to remove gotos, and it is difficult to decide whena goto serves a legitimate purpose and the rule should be deviated.In general, the 'style' suites have more violations which are easier to fix, andthe 'safety' suites have fewer violation that are harder to fix but warrant moreattention to address. Project authors can therefore enable both with the'default' suite, or pick between the two kinds suitable for their project andgoals.
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.
Pull Request Overview
This PR introduces baseline query suites for C/C++ by categorizing selected queries from MISRA, AUTOSAR, and CERT standards into "style" and "safety" categories. The baseline queries are hand-picked based on violation frequency, accuracy, broad applicability, and severity analysis on real projects.
- Adds
coding-standards/baseline/styleandcoding-standards/baseline/safetytags to 100+ existing query files - Creates new baseline query suite packages for both C and C++
- Provides three suite options: default (both style and safety), style-only, and safety-only
Reviewed Changes
Copilot reviewed 300 out of 417 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| cpp/autosar/src/rules/**/*.ql | Added baseline tags (style/safety) to AUTOSAR C++ rules based on categorization criteria |
| c/misra/src/rules/**/*.ql | Added baseline tags (style/safety) to MISRA C rules |
| c/cert/src/rules/**/*.ql | Added baseline tags (style/safety) to CERT C rules |
| c/baseline_suites/* | Created new C baseline query suite package with suite definitions |
| cpp/baseline_suites/* | Created new C++ baseline query suite package (referenced but not shown in diff) |
| .codeqlmanifest.json | Registered new baseline suite packages |
💡Add Copilot custom instructions for smarter, more guided reviews.Learn how to get started.
Description
These are queries from MISRA, AUTOSAR, and CERT, that have been hand picked based on a few properties:
The baseline rules have been divided into two categories, "style," and "safety." The choice of which is subjective, but as a general rule:
Some rules are in both suites -- for instance, rules that ban the use of 'goto' are conceivably both "style" and "safety." While goto is not erroneous in itself, and gotos are easy to spot during human review, it is typically not a simple task to refactor code to remove gotos, and it is difficult to decide when a goto serves a legitimate purpose and the rule should be deviated.
In general, the 'style' suites have more violations which are easier to fix, and the 'safety' suites have fewer violation that are harder to fix but warrant more attention to address. Project authors can therefore enable both with the 'default' suite, or pick between the two kinds suitable for their project and goals.
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 ofshared 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.