Skip to content

Commit 71f6d17

Browse files
committed
Rule 15.5: Exclude functions without user bodies
* Fix bracketing * Exclude compiler generated functions and functions without bodies.
1 parent 1dffd73 commit 71f6d17

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

c/misra/src/rules/RULE-15-5/FunctionReturnCondition.ql

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ import codingstandards.c.misra
1818
from Function func, string message
1919
where
2020
not isExcluded(func, Statements5Package::functionReturnConditionQuery()) and
21-
count(ReturnStmt return | return.getEnclosingFunction() = func) > 1 and
22-
message = "Function has more than on return statement."
23-
or
24-
not func.getBlock().getLastStmt() instanceof ReturnStmt and
25-
message = "The last statement of the function is not a return statement."
21+
func.hasDefinition() and
22+
not func.isCompilerGenerated() and
23+
(
24+
count(ReturnStmt return | return.getEnclosingFunction() = func) > 1 and
25+
message = "Function has more than on return statement."
26+
or
27+
not func.getBlock().getLastStmt() instanceof ReturnStmt and
28+
message = "The last statement of the function is not a return statement."
29+
)
2630
select func, message

c/misra/test/rules/RULE-15-5/test.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ void f4(int p1) { // NON_COMPLIANT
2424
}
2525
return;
2626
p1++;
27-
}
27+
}
28+
29+
void f5(); // Ignored - no body

0 commit comments

Comments
 (0)