- Notifications
You must be signed in to change notification settings - Fork70
Implement Rule 17.6#280
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
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
3 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
21 changes: 21 additions & 0 deletionsc/misra/src/rules/RULE-17-6/UseOfArrayStatic.ql
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /** | ||
| * @id c/misra/use-of-array-static | ||
| * @name RULE-17-6: The declaration of an array parameter shall not contain the static keyword between the [ ] | ||
| * @description Using the static keyword in an array type is error prone, and relies on the | ||
| * programmer to adhere to the guarantees to avoid undefined behavior. | ||
| * @kind problem | ||
| * @precision very-high | ||
| * @problem.severity error | ||
| * @tags external/misra/id/rule-17-6 | ||
| * correctness | ||
| * external/misra/obligation/mandatory | ||
| */ | ||
| import cpp | ||
| import codingstandards.c.misra | ||
| from Parameter p | ||
| where | ||
| not isExcluded(p, StaticPackage::useOfArrayStaticQuery()) and | ||
| p.getType().(ArrayType).hasSpecifier("static") | ||
| select p, "Parameter " + p + " is declared as an array type using the static keyword." |
3 changes: 3 additions & 0 deletionsc/misra/test/rules/RULE-17-6/UseOfArrayStatic.expected
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| | test.c:2:33:2:36 | arr2 | Parameter arr2 is declared as an array type using the static keyword. | | ||
| | test.c:3:39:3:42 | arr3 | Parameter arr3 is declared as an array type using the static keyword. | | ||
| | test.c:5:9:5:12 | arr4 | Parameter arr4 is declared as an array type using the static keyword. | |
1 change: 1 addition & 0 deletionsc/misra/test/rules/RULE-17-6/UseOfArrayStatic.qlref
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| rules/RULE-17-6/UseOfArrayStatic.ql |
8 changes: 8 additions & 0 deletionsc/misra/test/rules/RULE-17-6/test.c
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| void test_array(int arr1[10]) {} // COMPLIANT | ||
| void test_array_uses_static(int arr2[static 11]) {} // NON_COMPLIANT | ||
| void test_array_uses_static_multi(int arr3[static 12][5]) {} // NON_COMPLIANT | ||
| void test_array_uses_static_again( | ||
| int arr4[11]) { // COMPLIANT[FALSE_POSITIVE] - apparently a CodeQL | ||
| // bug where the static is associated with the fixed | ||
| // size | ||
| } |
3 changes: 3 additions & 0 deletionscpp/common/src/codingstandards/cpp/exclusions/c/RuleMetadata.qll
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
26 changes: 26 additions & 0 deletionscpp/common/src/codingstandards/cpp/exclusions/c/Static.qll
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| //** THIS FILE IS AUTOGENERATED, DO NOT MODIFY DIRECTLY. **/ | ||
| import cpp | ||
| import RuleMetadata | ||
| import codingstandards.cpp.exclusions.RuleMetadata | ||
| newtype StaticQuery = TUseOfArrayStaticQuery() | ||
| predicate isStaticQueryMetadata(Query query, string queryId, string ruleId, string category) { | ||
| query = | ||
| // `Query` instance for the `useOfArrayStatic` query | ||
| StaticPackage::useOfArrayStaticQuery() and | ||
| queryId = | ||
| // `@id` for the `useOfArrayStatic` query | ||
| "c/misra/use-of-array-static" and | ||
| ruleId = "RULE-17-6" and | ||
| category = "mandatory" | ||
| } | ||
| module StaticPackage { | ||
| Query useOfArrayStaticQuery() { | ||
| //autogenerate `Query` type | ||
| result = | ||
| // `Query` type for `useOfArrayStatic` query | ||
| TQueryC(TStaticPackageQuery(TUseOfArrayStaticQuery())) | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletionsrule_packages/c/Static.json
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| { | ||
| "MISRA-C-2012": { | ||
| "RULE-17-6": { | ||
| "properties": { | ||
| "obligation": "mandatory" | ||
| }, | ||
| "queries": [ | ||
| { | ||
| "description": "Using the static keyword in an array type is error prone, and relies on the programmer to adhere to the guarantees to avoid undefined behavior.", | ||
| "kind": "problem", | ||
| "name": "The declaration of an array parameter shall not contain the static keyword between the [ ]", | ||
| "precision": "very-high", | ||
| "severity": "error", | ||
| "short_name": "UseOfArrayStatic", | ||
| "tags": [ | ||
| "correctness" | ||
| ], | ||
| "implementation_scope": { | ||
| "description": "The static keyword is associated with particular array types in our model. This means we can get false positives when two parameter use the same array type and size, but only one of which uses the `static` keyword." | ||
| } | ||
| } | ||
| ], | ||
| "title": "The declaration of an array parameter shall not contain the static keyword between the [ ]" | ||
| } | ||
| } | ||
| } |
2 changes: 1 addition & 1 deletionrules.csv
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
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.