Skip to content

Commit 2b76aad

Browse files
committed
Added RULE-17-2
1 parent 84b1e8e commit 2b76aad

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @id c/misra/recursive-function-condition
3+
* @name RULE-17-2: Functions shall not call themselves, either directly or indirectly
4+
* @description Recursive function may cause memory and system failure issues.
5+
* @kind problem
6+
* @precision very-high
7+
* @problem.severity error
8+
* @tags external/misra/id/rule-17-2
9+
* maintainability
10+
* correctness
11+
* external/misra/obligation/required
12+
*/
13+
14+
import cpp
15+
import codingstandards.c.misra
16+
17+
from FunctionCall call, string msg, FunctionCall fc
18+
where
19+
not isExcluded(fc, Statements3Package::recursiveFunctionConditionQuery()) and
20+
fc.getTarget() = call.getTarget() and
21+
call.getTarget().calls*(call.getEnclosingFunction()) and
22+
if fc.getTarget() = fc.getEnclosingFunction()
23+
then msg = "This call directly invokes its containing function $@."
24+
else
25+
msg =
26+
"The function " + fc.getEnclosingFunction() + " is indirectly recursive via this call to $@."
27+
select fc, msg, fc.getTarget(), fc.getTarget().getName()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
| test.c:8:3:8:4 | call to f3 | This call directly invokes its containing function $@. | test.c:7:6:7:7 | f3 | f3 |
2+
| test.c:11:3:11:4 | call to f3 | The function f6 is indirectly recursive via this call to $@. | test.c:7:6:7:7 | f3 | f3 |
3+
| test.c:15:3:15:4 | call to f2 | The function f5 is indirectly recursive via this call to $@. | test.c:17:6:17:7 | f2 | f2 |
4+
| test.c:18:3:18:4 | call to f5 | The function f2 is indirectly recursive via this call to $@. | test.c:14:6:14:7 | f5 | f5 |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rules/RULE-17-2/RecursiveFunctionCondition.ql
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
void f1();
2+
void f2();
3+
void f4(int p1) { // COMPLIANT
4+
f1();
5+
}
6+
7+
void f3() {
8+
f3(); // NON_COMPLIANT
9+
}
10+
void f6() {
11+
f3(); // NON_COMPLIANT
12+
}
13+
14+
void f5() {
15+
f2(); // NON_COMPLIANT
16+
}
17+
void f2() {
18+
f5(); // NON_COMPLIANT
19+
}

0 commit comments

Comments
 (0)