Skip to content

Commit f45932d

Browse files
committed
Declarations1: improve RULE-5-1
1 parent 1cb417c commit f45932d

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

c/misra/src/rules/RULE-5-1/ExternalIdentifiersNotDistinct.ql

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import codingstandards.cpp.Linkage
1818

1919
class ExternalIdentifiers extends Declaration {
2020
ExternalIdentifiers() {
21-
this.getName().length() > 31 and
21+
this.getName().length() >= 31 and
2222
hasExternalLinkage(this) and
2323
getNamespace() instanceof GlobalNamespace and
2424
not this.isFromTemplateInstantiation(_) and
@@ -35,8 +35,6 @@ class ExternalIdentifiers extends Declaration {
3535
//C90 is not currently considered by this rule
3636
result = this.getName().prefix(31)
3737
}
38-
39-
string getNonSignificantName() { result = this.getName().suffix(31) }
4038
}
4139

4240
from ExternalIdentifiers d, ExternalIdentifiers d2
@@ -45,7 +43,7 @@ where
4543
not d = d2 and
4644
d.getLocation().getStartLine() >= d2.getLocation().getStartLine() and
4745
d.getSignificantName() = d2.getSignificantName() and
48-
not d.getNonSignificantName() = d2.getNonSignificantName()
46+
not d.getName() = d2.getName()
4947
select d,
50-
"External identifer " + d.getName() + " is nondistinct in first 31 characters, compared to $@.",
51-
d2, d2.getName()
48+
"External identifer " + d.getName() +
49+
" is nondistinct in characters at or over 31 limit, compared to $@.", d2, d2.getName()
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
| test.c:2:5:2:36 | iltiqzxgfqsgigwfuyntzghvzltueeeB | External identifer iltiqzxgfqsgigwfuyntzghvzltueeeB is nondistinct in first 31 characters, compared to $@. | test.c:1:5:1:36 | iltiqzxgfqsgigwfuyntzghvzltueeeA | iltiqzxgfqsgigwfuyntzghvzltueeeA |
1+
| test.c:2:5:2:36 | iltiqzxgfqsgigwfuyntzghvzltueeeB | External identifer iltiqzxgfqsgigwfuyntzghvzltueeeB is nondistinct in characters at or over 31 limit, compared to $@. | test.c:1:5:1:36 | iltiqzxgfqsgigwfuyntzghvzltueeeA | iltiqzxgfqsgigwfuyntzghvzltueeeA |
2+
| test.c:5:5:5:35 | iltiqzxgfqsgigwfuyntzghvzltueea | External identifer iltiqzxgfqsgigwfuyntzghvzltueea is nondistinct in characters at or over 31 limit, compared to $@. | test.c:4:5:4:36 | iltiqzxgfqsgigwfuyntzghvzltueeaZ | iltiqzxgfqsgigwfuyntzghvzltueeaZ |
3+
| test.c:8:5:8:35 | iltiqzxgfqsgigwfuyntzghvzltueee | External identifer iltiqzxgfqsgigwfuyntzghvzltueee is nondistinct in characters at or over 31 limit, compared to $@. | test.c:1:5:1:36 | iltiqzxgfqsgigwfuyntzghvzltueeeA | iltiqzxgfqsgigwfuyntzghvzltueeeA |
4+
| test.c:8:5:8:35 | iltiqzxgfqsgigwfuyntzghvzltueee | External identifer iltiqzxgfqsgigwfuyntzghvzltueee is nondistinct in characters at or over 31 limit, compared to $@. | test.c:2:5:2:36 | iltiqzxgfqsgigwfuyntzghvzltueeeB | iltiqzxgfqsgigwfuyntzghvzltueeeB |

c/misra/test/rules/RULE-5-1/test.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
int iltiqzxgfqsgigwfuyntzghvzltueeeA; // NON_COMPLIANT
1+
int iltiqzxgfqsgigwfuyntzghvzltueeeA; // NON_COMPLIANT - length 32
22
int iltiqzxgfqsgigwfuyntzghvzltueeeB; // NON_COMPLIANT
33

4-
int iltiqzxgfqsgigwfuyntzghvzltueee; // COMPLIANT
5-
int iltiqzxgfqsgigwfuyntzghvzltueee; // COMPLIANT
4+
int iltiqzxgfqsgigwfuyntzghvzltueeaZ; // NON_COMPLIANT - length 32
5+
int iltiqzxgfqsgigwfuyntzghvzltueea; // NON_COMPLIANT - length 31
6+
7+
int iltiqzxgfqsgigwfuyntzghvzltueee; // NON_COMPLIANT - length 31
8+
int iltiqzxgfqsgigwfuyntzghvzltueee; // NON_COMPLIANT
9+
10+
int iltiqzxgfqsgigwfuyntzghvzltuee; // COMPLIANT - length 30
11+
int iltiqzxgfqsgigwfuyntzghvzltuee; // COMPLIANT
612

713
int var1; // COMPLIANT
814
int var2; // COMPLIANT

0 commit comments

Comments
 (0)