Skip to content

Commit b21f35b

Browse files
author
Nikita Kraiouchkine
committed
Resolve RULE-11-1 false-negative
1 parent 214ac2c commit b21f35b

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

c/misra/src/rules/RULE-11-1/ConversionBetweenFunctionPointerAndOtherType.ql

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,5 @@ where
2525
// exception 1 (null pointer constant)
2626
not isNullPointerConstant(cast.getExpr()) and
2727
// exception 2 (conversion to void)
28-
not newType instanceof VoidType and
29-
// exception 3 (implicit conversion of function to function pointer)
30-
not (
31-
cast.isImplicit() and
32-
newType instanceof FunctionPointerType and
33-
cast.getExpr() instanceof FunctionAccess
34-
)
28+
not newType instanceof VoidType
3529
select cast, "Cast performed between a function pointer and another type."

c/misra/test/rules/RULE-11-1/ConversionBetweenFunctionPointerAndOtherType.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
| test.c:12:14:12:23 | (void *)... | Cast performed between a function pointer and another type. |
44
| test.c:14:8:14:15 | (fp2)... | Cast performed between a function pointer and another type. |
55
| test.c:15:8:15:15 | (fp2)... | Cast performed between a function pointer and another type. |
6+
| test.c:22:12:22:13 | (fp1)... | Cast performed between a function pointer and another type. |

c/misra/test/rules/RULE-11-1/test.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ void f1(void) {
1818
(void)(*v4()); // COMPLIANT
1919

2020
extern void f2(int p1);
21-
f2(0); // COMPLIANT
22-
fp1 v5 = f2; // COMPLIANT
21+
f2(0); // COMPLIANT
22+
fp1 v5 = f2; // NON_COMPLIANT
23+
fp2 v6 = f2; // COMPLIANT
24+
v5 = v1; // COMPLIANT
25+
v5 = v2; // NON_COMPLIANT
26+
v5 = (void (*)(void))v1; // COMPLIANT
27+
v5 = (void (*)(void))v2; // NON_COMPLIANT
2328
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- `RULE-11-1` - `ConversionBetweenFunctionPointerAndOtherType.ql`:
2+
- A result is now reported for an implicit conversion of a pointer to a function into a pointer to a function with an incompatible type.
3+
- Modified the test to reflect the fixed coverage.

0 commit comments

Comments
 (0)