Skip to content

Commit 0745848

Browse files
committed
Address review comments
1 parent 52e383a commit 0745848

File tree

4 files changed

+41
-14
lines changed

4 files changed

+41
-14
lines changed

cpp/misra/src/rules/RULE-5-0-1/TrigraphLikeSequencesShouldNotBeUsed.ql

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* @precision medium
77
* @problem.severity warning
88
* @tags external/misra/id/rule-5-0-1
9+
* portability
910
* readability
1011
* scope/single-translation-unit
1112
* external/misra/enforcement/decidable
@@ -15,10 +16,28 @@
1516
import cpp
1617
import codingstandards.cpp.misra
1718

18-
from StringLiteral s, int occurrenceOffset
19+
class CanContainSequenceType extends Locatable {
20+
CanContainSequenceType() {
21+
this instanceof StringLiteral
22+
or
23+
this instanceof Comment
24+
or
25+
this instanceof Macro
26+
}
27+
28+
string getContent() {
29+
result = this.(StringLiteral).getValue()
30+
or
31+
result = this.(Comment).getContents()
32+
or
33+
result = this.(Macro).getBody()
34+
}
35+
}
36+
37+
from CanContainSequenceType s, int occurrenceOffset, string substring
1938
where
2039
not isExcluded(s, TrigraphPackage::trigraphLikeSequencesShouldNotBeUsedQuery()) and
21-
exists(s.getValue().regexpFind("\\?\\?[=/'()!<>-]", _, occurrenceOffset)) and
40+
substring = s.getContent().regexpFind("\\?\\?[=/'()!<>-]", _, occurrenceOffset) and
2241
//one escape character is enough to mean this isnt a trigraph-like sequence
23-
not exists(s.getASimpleEscapeSequence(_, occurrenceOffset + 1))
24-
select s, "Trigraph-like sequence used in string literal."
42+
not exists(s.(StringLiteral).getASimpleEscapeSequence(_, occurrenceOffset + 1))
43+
select s, "Trigraph-like sequence found: '" + substring + "'."
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
| test.cpp:1:17:1:21 | ??= | Trigraph-like sequence used in string literal. |
2-
| test.cpp:2:18:2:22 | ??/ | Trigraph-like sequence used in string literal. |
3-
| test.cpp:3:18:3:22 | ??' | Trigraph-like sequence used in string literal. |
4-
| test.cpp:4:18:4:22 | ??( | Trigraph-like sequence used in string literal. |
5-
| test.cpp:5:18:5:22 | ??) | Trigraph-like sequence used in string literal. |
6-
| test.cpp:6:18:6:22 | ??! | Trigraph-like sequence used in string literal. |
7-
| test.cpp:7:18:7:22 | ??< | Trigraph-like sequence used in string literal. |
8-
| test.cpp:8:18:8:22 | ??> | Trigraph-like sequence used in string literal. |
9-
| test.cpp:9:18:9:22 | ??- | Trigraph-like sequence used in string literal. |
1+
| test.cpp:1:17:1:21 | ??= | Trigraph-like sequence found: '??='. |
2+
| test.cpp:2:18:2:22 | ??/ | Trigraph-like sequence found: '??/'. |
3+
| test.cpp:3:18:3:22 | ??' | Trigraph-like sequence found: '??''. |
4+
| test.cpp:4:18:4:22 | ??( | Trigraph-like sequence found: '??('. |
5+
| test.cpp:5:18:5:22 | ??) | Trigraph-like sequence found: '??)'. |
6+
| test.cpp:6:18:6:22 | ??! | Trigraph-like sequence found: '??!'. |
7+
| test.cpp:7:18:7:22 | ??< | Trigraph-like sequence found: '??<'. |
8+
| test.cpp:8:18:8:22 | ??> | Trigraph-like sequence found: '??>'. |
9+
| test.cpp:9:18:9:22 | ??- | Trigraph-like sequence found: '??-'. |
10+
| test.cpp:14:1:14:45 | // comment trigraph-like ??= // NON_COMPLIANT | Trigraph-like sequence found: '??='. |
11+
| test.cpp:17:1:17:25 | #define TRIGRAPH_LIKE ??= | Trigraph-like sequence found: '??='. |

cpp/misra/test/rules/RULE-5-0-1/test.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,9 @@ const char *g7 = "??>"; // NON_COMPLIANT
99
const char *g8 = "??-"; // NON_COMPLIANT
1010

1111
const char *g9 = "\?\?="; // COMPLIANT
12-
const char *g10 = "?="; // COMPLIANT
12+
const char *g10 = "?="; // COMPLIANT
13+
14+
// comment trigraph-like ??= // NON_COMPLIANT
15+
16+
// clang-format off
17+
#define TRIGRAPH_LIKE ??= // NON_COMPLIANT - format off otherwise it separates the characters

rule_packages/cpp/Trigraph.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"severity": "warning",
1515
"short_name": "TrigraphLikeSequencesShouldNotBeUsed",
1616
"tags": [
17+
"portability",
1718
"readability",
1819
"scope/single-translation-unit"
1920
],

0 commit comments

Comments
 (0)