Skip to content

Commit 949450a

Browse files
Add defense against cpp code based on MRVA results. Add comments.
1 parent c9ced08 commit 949450a

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,18 @@ import cpp
1515
import codingstandards.c.misra
1616

1717
predicate isImplicitlyAddressed(FunctionAccess access) {
18-
not access.getParent() instanceof AddressOfExpr or
19-
exists(ParenthesisExpr parens | parens.getExpr() = 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
25+
// Note: the following *seems* to only exist in c++ codebases, for instance,
26+
// when calling a member. In c, this syntax should always extract as a
27+
// [FunctionCall] rather than a [ExprCall] of a [FunctionAccess]. Still, this
28+
// is a good pattern to be defensive against.
29+
not exists(ExprCall call | call.getExpr() = access)
2030
}
2131

2232
from FunctionAccess funcAccess

0 commit comments

Comments
 (0)