-
Notifications
You must be signed in to change notification settings - Fork 73
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
Open
knewbury01
wants to merge
3
commits into
github:main
Choose a base branch
from
knewbury01:knewbury01/trigraphs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 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())) | ||
| } | ||
| } |
24 changes: 24 additions & 0 deletions
24
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,24 @@ | ||
| /** | ||
| * @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 | ||
| * readability | ||
| * scope/single-translation-unit | ||
| * external/misra/enforcement/decidable | ||
| * external/misra/obligation/advisory | ||
| */ | ||
|
|
||
| import cpp | ||
| import codingstandards.cpp.misra | ||
|
|
||
| from StringLiteral s, int occurrenceOffset | ||
| where | ||
| not isExcluded(s, TrigraphPackage::trigraphLikeSequencesShouldNotBeUsedQuery()) and | ||
| exists(s.getValue().regexpFind("\\?\\?[=/'()!<>-]", _, occurrenceOffset)) and | ||
| //one escape character is enough to mean this isnt a trigraph-like sequence | ||
| not exists(s.getASimpleEscapeSequence(_, occurrenceOffset + 1)) | ||
| select s, "Trigraph-like sequence used in string literal." | ||
9 changes: 9 additions & 0 deletions
9
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,9 @@ | ||
| | test.cpp:1:17:1:21 | ??= | Trigraph-like sequence used in string literal. | | ||
| | test.cpp:2:18:2:22 | ??/ | Trigraph-like sequence used in string literal. | | ||
| | test.cpp:3:18:3:22 | ??' | Trigraph-like sequence used in string literal. | | ||
| | test.cpp:4:18:4:22 | ??( | Trigraph-like sequence used in string literal. | | ||
| | test.cpp:5:18:5:22 | ??) | Trigraph-like sequence used in string literal. | | ||
| | test.cpp:6:18:6:22 | ??! | Trigraph-like sequence used in string literal. | | ||
| | test.cpp:7:18:7:22 | ??< | Trigraph-like sequence used in string literal. | | ||
| | test.cpp:8:18:8:22 | ??> | Trigraph-like sequence used in string literal. | | ||
| | test.cpp:9:18:9:22 | ??- | Trigraph-like sequence used in string literal. | |
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,12 @@ | ||
| 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 |
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,28 @@ | ||
| { | ||
| "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": [ | ||
| "readability", | ||
| "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.
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.
The comment
//one escape character is enough to mean this isnt a trigraph-like sequencecontains a spelling/grammar issue;isntshould be written asisn'tfor clarity and consistency with surrounding documentation comments.