Skip to content

Commit 4e11863

Browse files
committed
Declarations1: improve alert message rules 5-1 and 5-4
1 parent a1380bb commit 4e11863

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ class ExternalIdentifiersLong extends ExternalIdentifiers {
2424
ExternalIdentifiersLong() { this.getName().length() >= 32 }
2525
}
2626

27-
predicate notSame(ExternalIdentifiers d, ExternalIdentifiers d2) { not d = d2 }
27+
predicate notSame(ExternalIdentifiers d, ExternalIdentifiers d2) {
28+
not d = d2 and
29+
d.getLocation().getStartLine() >= d2.getLocation().getStartLine()
30+
}
2831

2932
from ExternalIdentifiers d, ExternalIdentifiers d2
3033
where

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515
import cpp
1616
import codingstandards.c.misra
1717

18-
from Macro m
18+
from Macro m, Macro m2
1919
where
2020
not isExcluded(m, Declarations1Package::macroIdentifiersNotDistinctQuery()) and
21-
exists(Macro m2 |
22-
not m = m2 and
21+
not m = m2 and
22+
(
2323
if m.getName().length() >= 64
2424
then m.getName().substring(0, 62) = m2.getName().substring(0, 62)
2525
else m.getName() = m2.getName()
26-
)
27-
select m, "Nondistinct macro identifer used " + m.getName() + " ."
26+
) and
27+
//reduce double report since both macros are in alert, arbitrary ordering
28+
m.getLocation().getStartLine() >= m2.getLocation().getStartLine()
29+
select m, "Nondistinct macro identifer used " + m.getName() + " compared to $@.", m2, m2.getName()
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
| test.c:1:1:1:72 | #define iltiqzxgfqsgigwfuyntzghvzltueatcxqnqofnnvjyszmcsylyohvqaosjbqyyA | Nondistinct macro identifer used iltiqzxgfqsgigwfuyntzghvzltueatcxqnqofnnvjyszmcsylyohvqaosjbqyyA . |
2-
| test.c:2:1:2:72 | #define iltiqzxgfqsgigwfuyntzghvzltueatcxqnqofnnvjyszmcsylyohvqaosjbqyyB | Nondistinct macro identifer used iltiqzxgfqsgigwfuyntzghvzltueatcxqnqofnnvjyszmcsylyohvqaosjbqyyB . |
3-
| test.c:7:1:7:57 | #define FUNCTION_MACRO(FUNCTION_MACRO) FUNCTION_MACRO + 1 | Nondistinct macro identifer used FUNCTION_MACRO . |
4-
| test.c:8:1:8:31 | #define FUNCTION_MACRO(X) X + 1 | Nondistinct macro identifer used FUNCTION_MACRO . |
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 |

0 commit comments

Comments
 (0)