diff --git a/c/common/src/codingstandards/c/Identifiers.qll b/c/common/src/codingstandards/c/Identifiers.qll index c100747cfb..580cd8cfdd 100644 --- a/c/common/src/codingstandards/c/Identifiers.qll +++ b/c/common/src/codingstandards/c/Identifiers.qll @@ -12,5 +12,8 @@ class InterestingIdentifiers extends Declaration { exists(this.getADeclarationLocation()) } - string getSignificantName() { result = this.getName().prefix(31) } + //this definition of significant relies on the number of significant characters for a macro name (C99) + //this is used on macro name comparisons only + //not necessarily against other types of identifiers + string getSignificantNameComparedToMacro() { result = this.getName().prefix(63) } } diff --git a/c/misra/src/rules/RULE-5-5/IdentifiersNotDistinctFromMacroNames.ql b/c/misra/src/rules/RULE-5-5/IdentifiersNotDistinctFromMacroNames.ql index ff0b730e1f..2ee6ef26d2 100644 --- a/c/misra/src/rules/RULE-5-5/IdentifiersNotDistinctFromMacroNames.ql +++ b/c/misra/src/rules/RULE-5-5/IdentifiersNotDistinctFromMacroNames.ql @@ -22,10 +22,12 @@ where not isExcluded(i, Declarations3Package::identifiersNotDistinctFromMacroNamesQuery()) and mName = iName and ( - //C99 states the first 31 characters of external identifiers are significant - //C90 states the first 6 characters of external identifiers are significant and case is not required to be significant + //C99 states the first 63 characters of macro identifiers are significant + //C90 states the first 31 characters of macro identifiers are significant //C90 is not currently considered by this rule - if m.getName().length() > 31 then mName = m.getName().prefix(31) else mName = m.getName() + if m.getName().length() > 63 then mName = m.getName().prefix(63) else mName = m.getName() ) and - if i.getName().length() > 31 then iName = i.getSignificantName() else iName = i.getName() + if i.getName().length() > 63 + then iName = i.getSignificantNameComparedToMacro() + else iName = i.getName() select m, "Macro name is nonunique compared to $@.", i, i.getName() diff --git a/c/misra/test/rules/RULE-5-5/IdentifiersNotDistinctFromMacroNames.expected b/c/misra/test/rules/RULE-5-5/IdentifiersNotDistinctFromMacroNames.expected index bf8cf218d8..5874d1f6f5 100644 --- a/c/misra/test/rules/RULE-5-5/IdentifiersNotDistinctFromMacroNames.expected +++ b/c/misra/test/rules/RULE-5-5/IdentifiersNotDistinctFromMacroNames.expected @@ -1,2 +1,2 @@ | 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 | -| test.c:6:1:6:42 | #define iltiqzxgfqsgigwfuyntzghvzltueeaZ ; | Macro name is nonunique compared to $@. | test.c:7:12:7:43 | iltiqzxgfqsgigwfuyntzghvzltueeaQ | iltiqzxgfqsgigwfuyntzghvzltueeaQ | +| test.c:6:1:6:72 | #define iltiqzxgfqsgigwfuyntzghvzltueatcxqnqofnnvjyszmcsylyohvqaosjbqyyA | Macro name is nonunique compared to $@. | test.c:11:5:11:68 | iltiqzxgfqsgigwfuyntzghvzltueatcxqnqofnnvjyszmcsylyohvqaosjbqyyB | iltiqzxgfqsgigwfuyntzghvzltueatcxqnqofnnvjyszmcsylyohvqaosjbqyyB | diff --git a/c/misra/test/rules/RULE-5-5/test.c b/c/misra/test/rules/RULE-5-5/test.c index 6ae5c4c871..914c42386d 100644 --- a/c/misra/test/rules/RULE-5-5/test.c +++ b/c/misra/test/rules/RULE-5-5/test.c @@ -3,5 +3,12 @@ int Sum; -#define iltiqzxgfqsgigwfuyntzghvzltueeaZ ; // NON_COMPLIANT - length 32 -static int iltiqzxgfqsgigwfuyntzghvzltueeaQ; // NON_COMPLIANT - length 32 \ No newline at end of file +#define iltiqzxgfqsgigwfuyntzghvzltueatcxqnqofnnvjyszmcsylyohvqaosjbqyyA // NON_COMPLIANT + // - + // length + // 64 +static int + iltiqzxgfqsgigwfuyntzghvzltueatcxqnqofnnvjyszmcsylyohvqaosjbqyyB; // NON_COMPLIANT + // - + // length + // 64 \ No newline at end of file