Skip to content

Commit 5e8e2ff

Browse files
committed
Fix RULE-8-4
1 parent b8161e8 commit 5e8e2ff

File tree

5 files changed

+12
-19
lines changed

5 files changed

+12
-19
lines changed

c/misra/src/rules/RULE-8-4/CompatibleDeclarationObjectDefined.ql

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,10 @@ where
2323
not isExcluded(decl1, Declarations4Package::compatibleDeclarationObjectDefinedQuery()) and
2424
decl1.isDefinition() and
2525
decl1.getDeclaration() instanceof ExternalIdentifiers and
26-
(
27-
//no declaration matches exactly
28-
not exists(VariableDeclarationEntry decl2 |
29-
not decl2.isDefinition() and decl2.getDeclaration() = decl1.getDeclaration()
30-
) and
31-
//and none is close enough
32-
not exists(VariableDeclarationEntry decl2 |
33-
not decl2.isDefinition() and
34-
decl1.getVariable().getQualifiedName() = decl2.getVariable().getQualifiedName() and
35-
typesCompatible(decl1.getType(), decl2.getType())
36-
)
26+
// no declaration matches
27+
not exists(VariableDeclarationEntry decl2 |
28+
not decl2.isDefinition() and
29+
decl1.getVariable().getQualifiedName() = decl2.getVariable().getQualifiedName() and
30+
typesCompatible(decl1.getType(), decl2.getType())
3731
)
3832
select decl1, "No separate compatible declaration found for this definition."
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
| function2.c:5:6:5:7 | definition of f3 | No separate compatible declaration found for this definition. |
2-
| function2.c:7:6:7:7 | definition of f4 | No separate compatible declaration found for this definition. |
1+
| object1.c:4:12:4:13 | definition of i1 | No separate compatible declaration found for this definition. |
2+
| object1.c:6:5:6:6 | definition of i2 | No separate compatible declaration found for this definition. |
3+
| object2.c:1:7:1:8 | definition of i3 | No separate compatible declaration found for this definition. |

c/misra/test/rules/RULE-8-4/object1.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
extern int i;
2-
i = 0; // COMPLIANT
2+
int i = 0; // COMPLIANT
33

44
extern int i1 = 0; // NON_COMPLIANT
55

66
int i2 = 0; // NON_COMPLIANT
77

8-
// not detected as `short i3` exists
9-
extern int i3; // NON_COMPLIANT[FALSE_NEGATIVE]
8+
extern int i3;
109

11-
extern int i4; // COMPLIANT
10+
extern int i4;

c/misra/test/rules/RULE-8-4/object2.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// not detected as `extern int i3` exists
2-
short i3 = 0; // NON_COMPLIANT[FALSE_NEGATIVE]
1+
short i3 = 0; // NON_COMPLIANT
32

43
signed int i4 = 0; // COMPLIANT

c/misra/test/rules/RULE-8-4/test.c

Whitespace-only changes.

0 commit comments

Comments
 (0)