Skip to content

Commit 4081fc8

Browse files
authored
Merge pull request #98 from knewbury01/knewbury01/Declarations3-patch-5-5
Declarations3: fix RULE-5-5
2 parents d39bdf4 + b9e85c4 commit 4081fc8

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

c/common/src/codingstandards/c/Identifiers.qll

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@ class InterestingIdentifiers extends Declaration {
1212
exists(this.getADeclarationLocation())
1313
}
1414

15-
string getSignificantName() { result = this.getName().prefix(31) }
15+
//this definition of significant relies on the number of significant characters for a macro name (C99)
16+
//this is used on macro name comparisons only
17+
//not necessarily against other types of identifiers
18+
string getSignificantNameComparedToMacro() { result = this.getName().prefix(63) }
1619
}

c/misra/src/rules/RULE-5-5/IdentifiersNotDistinctFromMacroNames.ql

+6-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ where
2222
not isExcluded(i, Declarations3Package::identifiersNotDistinctFromMacroNamesQuery()) and
2323
mName = iName and
2424
(
25-
//C99 states the first 31 characters of external identifiers are significant
26-
//C90 states the first 6 characters of external identifiers are significant and case is not required to be significant
25+
//C99 states the first 63 characters of macro identifiers are significant
26+
//C90 states the first 31 characters of macro identifiers are significant
2727
//C90 is not currently considered by this rule
28-
if m.getName().length() > 31 then mName = m.getName().prefix(31) else mName = m.getName()
28+
if m.getName().length() > 63 then mName = m.getName().prefix(63) else mName = m.getName()
2929
) and
30-
if i.getName().length() > 31 then iName = i.getSignificantName() else iName = i.getName()
30+
if i.getName().length() > 63
31+
then iName = i.getSignificantNameComparedToMacro()
32+
else iName = i.getName()
3133
select m, "Macro name is nonunique compared to $@.", i, i.getName()
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
| test.c:1:1:1:23 | #define Sum(x,y) x + y | Macro name is nonunique compared to $@. | test.c:4:5:4:7 | Sum | Sum |
2-
| test.c:6:1:6:42 | #define iltiqzxgfqsgigwfuyntzghvzltueeaZ ; | Macro name is nonunique compared to $@. | test.c:7:12:7:43 | iltiqzxgfqsgigwfuyntzghvzltueeaQ | iltiqzxgfqsgigwfuyntzghvzltueeaQ |
2+
| test.c:6:1:6:72 | #define iltiqzxgfqsgigwfuyntzghvzltueatcxqnqofnnvjyszmcsylyohvqaosjbqyyA | Macro name is nonunique compared to $@. | test.c:11:5:11:68 | iltiqzxgfqsgigwfuyntzghvzltueatcxqnqofnnvjyszmcsylyohvqaosjbqyyB | iltiqzxgfqsgigwfuyntzghvzltueatcxqnqofnnvjyszmcsylyohvqaosjbqyyB |

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

+9-2
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,12 @@
33

44
int Sum;
55

6-
#define iltiqzxgfqsgigwfuyntzghvzltueeaZ ; // NON_COMPLIANT - length 32
7-
static int iltiqzxgfqsgigwfuyntzghvzltueeaQ; // NON_COMPLIANT - length 32
6+
#define iltiqzxgfqsgigwfuyntzghvzltueatcxqnqofnnvjyszmcsylyohvqaosjbqyyA // NON_COMPLIANT
7+
// -
8+
// length
9+
// 64
10+
static int
11+
iltiqzxgfqsgigwfuyntzghvzltueatcxqnqofnnvjyszmcsylyohvqaosjbqyyB; // NON_COMPLIANT
12+
// -
13+
// length
14+
// 64

0 commit comments

Comments
 (0)