Skip to content

Commit a3891e2

Browse files
committed
Declarations1: improve alert messaages and substring predicate usage for RULE-5-1 and RULE-5-4
1 parent a75a79a commit a3891e2

File tree

4 files changed

+9
-7
lines changed

4 files changed

+9
-7
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ where
3737
//C90 states the first 6 characters of external identifiers are significant and case is not required to be significant
3838
//C90 is not currently considered by this rule
3939
if d instanceof ExternalIdentifiersLong and d2 instanceof ExternalIdentifiersLong
40-
then d.getName().substring(0, 30) = d2.getName().substring(0, 30)
40+
then d.getName().prefix(31) = d2.getName().prefix(31)
4141
else d.getName() = d2.getName()
42-
select d, "External identifer is nondistinct " + d.getName() + " compared to $@.", d2, d.getName()
42+
select d,
43+
"External identifer " + d.getName() + " is nondistinct in first 31 characters, compared to $@.",
44+
d2, d2.getName()

c/misra/src/rules/RULE-5-4/MacroIdentifiersNotDistinct.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ where
2525
//ie an identifier differing on the 32nd character would be indistinct for C90 but distinct for C99
2626
//and is currently not reported by this rule
2727
if m.getName().length() >= 64
28-
then m.getName().substring(0, 62) = m2.getName().substring(0, 62)
28+
then m.getName().prefix(63) = m2.getName().prefix(63)
2929
else m.getName() = m2.getName()
3030
) and
3131
//reduce double report since both macros are in alert, arbitrary ordering
3232
m.getLocation().getStartLine() >= m2.getLocation().getStartLine()
33-
select m, "Nondistinct macro identifer used " + m.getName() + " compared to $@.", m2, m2.getName()
33+
select m, "Macro identifer " + m.getName() + " is nondistinct in first 63 characters, compared to $@.", m2, m2.getName()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
| test.c:2:5:2:36 | iltiqzxgfqsgigwfuyntzghvzltueeeB | External identifer is nondistinct iltiqzxgfqsgigwfuyntzghvzltueeeB compared to $@. | test.c:1:5:1:36 | iltiqzxgfqsgigwfuyntzghvzltueeeA | iltiqzxgfqsgigwfuyntzghvzltueeeB |
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 |
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
| test.c:2:1:2:72 | #define iltiqzxgfqsgigwfuyntzghvzltueatcxqnqofnnvjyszmcsylyohvqaosjbqyyB | Nondistinct macro identifer used iltiqzxgfqsgigwfuyntzghvzltueatcxqnqofnnvjyszmcsylyohvqaosjbqyyB compared to $@. | test.c:1:1:1:72 | #define iltiqzxgfqsgigwfuyntzghvzltueatcxqnqofnnvjyszmcsylyohvqaosjbqyyA | iltiqzxgfqsgigwfuyntzghvzltueatcxqnqofnnvjyszmcsylyohvqaosjbqyyA |
2-
| test.c:8:1:8:31 | #define FUNCTION_MACRO(X) X + 1 | Nondistinct macro identifer used FUNCTION_MACRO compared to $@. | test.c:7:1:7:57 | #define FUNCTION_MACRO(FUNCTION_MACRO) FUNCTION_MACRO + 1 | FUNCTION_MACRO |
1+
| test.c:2:1:2:72 | #define iltiqzxgfqsgigwfuyntzghvzltueatcxqnqofnnvjyszmcsylyohvqaosjbqyyB | Macro identifer iltiqzxgfqsgigwfuyntzghvzltueatcxqnqofnnvjyszmcsylyohvqaosjbqyyB is nondistinct in first 63 characters, compared to $@. | test.c:1:1:1:72 | #define iltiqzxgfqsgigwfuyntzghvzltueatcxqnqofnnvjyszmcsylyohvqaosjbqyyA | iltiqzxgfqsgigwfuyntzghvzltueatcxqnqofnnvjyszmcsylyohvqaosjbqyyA |
2+
| test.c:8:1:8:31 | #define FUNCTION_MACRO(X) X + 1 | Macro identifer FUNCTION_MACRO is nondistinct in first 63 characters, compared to $@. | test.c:7:1:7:57 | #define FUNCTION_MACRO(FUNCTION_MACRO) FUNCTION_MACRO + 1 | FUNCTION_MACRO |

0 commit comments

Comments
 (0)