-
Notifications
You must be signed in to change notification settings - Fork 74
Add trigraph rule RULE-5-0-1 #1022
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
|---|---|---|
|
|
@@ -290,6 +290,7 @@ | |
| "Strings3", | ||
| "Syntax", | ||
| "Templates", | ||
| "Trigraph", | ||
| "TypeRanges", | ||
| "Lambdas", | ||
| "Pointers", | ||
|
|
||
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 deletions
26
cpp/common/src/codingstandards/cpp/exclusions/cpp/Trigraph.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 TrigraphQuery = TTrigraphLikeSequencesShouldNotBeUsedQuery() | ||
|
|
||
| predicate isTrigraphQueryMetadata(Query query, string queryId, string ruleId, string category) { | ||
| query = | ||
| // `Query` instance for the `trigraphLikeSequencesShouldNotBeUsed` query | ||
| TrigraphPackage::trigraphLikeSequencesShouldNotBeUsedQuery() and | ||
| queryId = | ||
| // `@id` for the `trigraphLikeSequencesShouldNotBeUsed` query | ||
| "cpp/misra/trigraph-like-sequences-should-not-be-used" and | ||
| ruleId = "RULE-5-0-1" and | ||
| category = "advisory" | ||
| } | ||
|
|
||
| module TrigraphPackage { | ||
| Query trigraphLikeSequencesShouldNotBeUsedQuery() { | ||
| //autogenerate `Query` type | ||
| result = | ||
| // `Query` type for `trigraphLikeSequencesShouldNotBeUsed` query | ||
| TQueryCPP(TTrigraphPackageQuery(TTrigraphLikeSequencesShouldNotBeUsedQuery())) | ||
| } | ||
| } |
43 changes: 43 additions & 0 deletions
43
cpp/misra/src/rules/RULE-5-0-1/TrigraphLikeSequencesShouldNotBeUsed.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,43 @@ | ||
| /** | ||
| * @id cpp/misra/trigraph-like-sequences-should-not-be-used | ||
| * @name RULE-5-0-1: Trigraph-like sequences should not be used | ||
| * @description Using trigraph-like sequences can lead to developer confusion. | ||
| * @kind problem | ||
| * @precision medium | ||
| * @problem.severity warning | ||
| * @tags external/misra/id/rule-5-0-1 | ||
| * maintainability | ||
| * readability | ||
| * scope/single-translation-unit | ||
| * external/misra/enforcement/decidable | ||
| * external/misra/obligation/advisory | ||
| */ | ||
|
|
||
| import cpp | ||
| import codingstandards.cpp.misra | ||
|
|
||
| class CanContainSequenceType extends Locatable { | ||
| CanContainSequenceType() { | ||
| this instanceof StringLiteral | ||
| or | ||
| this instanceof Comment | ||
| or | ||
| this instanceof Macro | ||
| } | ||
|
|
||
| string getContent() { | ||
| result = this.(StringLiteral).getValue() | ||
| or | ||
| result = this.(Comment).getContents() | ||
| or | ||
| result = this.(Macro).getBody() | ||
| } | ||
| } | ||
|
|
||
| from CanContainSequenceType s, int occurrenceOffset, string substring | ||
| where | ||
| not isExcluded(s, TrigraphPackage::trigraphLikeSequencesShouldNotBeUsedQuery()) and | ||
| substring = s.getContent().regexpFind("\\?\\?[=/'()!<>-]", _, occurrenceOffset) and | ||
| //one escape character is enough to mean this isnt a trigraph-like sequence | ||
| not exists(s.(StringLiteral).getASimpleEscapeSequence(_, occurrenceOffset + 1)) | ||
| select s, "Trigraph-like sequence found: '" + substring + "'." | ||
11 changes: 11 additions & 0 deletions
11
cpp/misra/test/rules/RULE-5-0-1/TrigraphLikeSequencesShouldNotBeUsed.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,11 @@ | ||
| | test.cpp:1:17:1:21 | ??= | Trigraph-like sequence found: '??='. | | ||
| | test.cpp:2:18:2:22 | ??/ | Trigraph-like sequence found: '??/'. | | ||
| | test.cpp:3:18:3:22 | ??' | Trigraph-like sequence found: '??''. | | ||
| | test.cpp:4:18:4:22 | ??( | Trigraph-like sequence found: '??('. | | ||
| | test.cpp:5:18:5:22 | ??) | Trigraph-like sequence found: '??)'. | | ||
| | test.cpp:6:18:6:22 | ??! | Trigraph-like sequence found: '??!'. | | ||
| | test.cpp:7:18:7:22 | ??< | Trigraph-like sequence found: '??<'. | | ||
| | test.cpp:8:18:8:22 | ??> | Trigraph-like sequence found: '??>'. | | ||
| | test.cpp:9:18:9:22 | ??- | Trigraph-like sequence found: '??-'. | | ||
| | test.cpp:14:1:14:45 | // comment trigraph-like ??= // NON_COMPLIANT | Trigraph-like sequence found: '??='. | | ||
| | test.cpp:17:1:17:25 | #define TRIGRAPH_LIKE ??= | Trigraph-like sequence found: '??='. | |
1 change: 1 addition & 0 deletions
1
cpp/misra/test/rules/RULE-5-0-1/TrigraphLikeSequencesShouldNotBeUsed.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-5-0-1/TrigraphLikeSequencesShouldNotBeUsed.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,17 @@ | ||
| const char *g = "??="; // NON_COMPLIANT | ||
| const char *g1 = "??/"; // NON_COMPLIANT | ||
| const char *g2 = "??'"; // NON_COMPLIANT | ||
| const char *g3 = "??("; // NON_COMPLIANT | ||
| const char *g4 = "??)"; // NON_COMPLIANT | ||
| const char *g5 = "??!"; // NON_COMPLIANT | ||
| const char *g6 = "??<"; // NON_COMPLIANT | ||
| const char *g7 = "??>"; // NON_COMPLIANT | ||
| const char *g8 = "??-"; // NON_COMPLIANT | ||
|
|
||
| const char *g9 = "\?\?="; // COMPLIANT | ||
| const char *g10 = "?="; // COMPLIANT | ||
|
|
||
| // comment trigraph-like ??= // NON_COMPLIANT | ||
|
|
||
| // clang-format off | ||
| #define TRIGRAPH_LIKE ??= // NON_COMPLIANT - format off otherwise it separates the characters |
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,29 @@ | ||
| { | ||
| "MISRA-C++-2023": { | ||
| "RULE-5-0-1": { | ||
| "properties": { | ||
| "enforcement": "decidable", | ||
| "obligation": "advisory" | ||
| }, | ||
| "queries": [ | ||
| { | ||
| "description": "Using trigraph-like sequences can lead to developer confusion.", | ||
| "kind": "problem", | ||
| "name": "Trigraph-like sequences should not be used", | ||
| "precision": "medium", | ||
| "severity": "warning", | ||
| "short_name": "TrigraphLikeSequencesShouldNotBeUsed", | ||
| "tags": [ | ||
| "maintainability", | ||
| "readability", | ||
knewbury01 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "scope/single-translation-unit" | ||
| ], | ||
| "implementation_scope": { | ||
| "description": "The rule checks within string literals only for trigraph-like sequences." | ||
| } | ||
| } | ||
| ], | ||
| "title": "Trigraph-like sequences should not be used" | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.