Skip to content

Commit 1007a53

Browse files
Allow &(f) under rule 17-12
1 parent a8d832b commit 1007a53

File tree

3 files changed

+7
-15
lines changed

3 files changed

+7
-15
lines changed

c/misra/src/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.ql

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

1717
predicate isImplicitlyAddressed(FunctionAccess access) {
18-
(
19-
not access.getParent() instanceof AddressOfExpr
20-
or
21-
// This catches "&(foo)", which could be considered to be somewhat less
22-
// readable than "(&foo)".
23-
exists(ParenthesisExpr parens | parens.getExpr() = access)
24-
) and
18+
not access.getParent() instanceof AddressOfExpr and
2519
// Note: the following *seems* to only exist in c++ codebases, for instance,
2620
// when calling a member. In c, this syntax should always extract as a
2721
// [FunctionCall] rather than a [ExprCall] of a [FunctionAccess]. Still, this

c/misra/test/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.expected

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
| test.c:14:25:14:29 | func2 | The address of function func2 is taken without the & operator. |
2-
| test.c:15:27:15:31 | func3 | The address of function func3 is taken without the & operator. |
2+
| test.c:15:25:15:29 | func3 | The address of function func3 is taken without the & operator. |
33
| test.c:21:12:21:16 | func1 | The address of function func1 is taken without the & operator. |
44
| test.c:38:3:38:7 | func1 | The address of function func1 is taken without the & operator. |
55
| test.c:39:3:39:7 | func2 | The address of function func2 is taken without the & operator. |
6-
| test.c:47:5:47:9 | func1 | The address of function func1 is taken without the & operator. |
7-
| test.c:48:5:48:9 | func2 | The address of function func2 is taken without the & operator. |
86
| test.c:57:13:57:17 | func1 | The address of function func1 is taken without the & operator. |
97
| test.c:58:21:58:25 | func2 | The address of function func2 is taken without the & operator. |
108
| test.c:59:13:59:17 | func1 | The address of function func1 is taken without the & operator. |

c/misra/test/rules/RULE-17-12/test.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ typedef void (*func_ptr_t1)();
1010
typedef void (*func_ptr_t2)(int x, char *y);
1111
typedef s (*func_ptr_t3)();
1212

13-
func_ptr_t1 func_ptr1 = &func1; // COMPLIANT
14-
func_ptr_t2 func_ptr2 = func2; // NON-COMPLIANT
15-
func_ptr_t3 func_ptr3 = &(func3); // NON-COMPLIANT
13+
func_ptr_t1 func_ptr1 = &func1; // COMPLIANT
14+
func_ptr_t2 func_ptr2 = func2; // NON-COMPLIANT
15+
func_ptr_t3 func_ptr3 = func3 + 0; // NON-COMPLIANT
1616

1717
void take_func(func_ptr_t1 f1, func_ptr_t2 f2);
1818

@@ -44,8 +44,8 @@ void test() {
4444
(func1)(); // COMPLIANT
4545
(func2)(1, "hello"); // COMPLIANT
4646

47-
&(func1); // NON-COMPLIANT
48-
&(func2); // NON-COMPLIANT
47+
&(func1); // COMPLIANT
48+
&(func2); // COMPLIANT
4949

5050
(&func1)(); // COMPLIANT
5151
(&func2)(1, "hello"); // COMPLIANT

0 commit comments

Comments
 (0)