Skip to content

Commit 298db28

Browse files
committed
Rule 17.2: Address performance/corretness issues
Simplify the query to only refer to one function call, which improves performance and addresses a correctness issue when a function calls a recursive function.
1 parent e462d66 commit 298db28

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

c/misra/src/rules/RULE-17-2/RecursiveFunctionCondition.ql

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@
1414
import cpp
1515
import codingstandards.c.misra
1616

17-
from FunctionCall call, string msg, FunctionCall fc
17+
from FunctionCall fc, Function f, string msg
1818
where
1919
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()
20+
fc.getEnclosingFunction() = f and
21+
fc.getTarget().calls*(f) and
22+
if fc.getTarget() = f
2323
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 $@."
24+
else msg = "The function " + f + " is indirectly recursive via this call to $@."
2725
select fc, msg, fc.getTarget(), fc.getTarget().getName()
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
| 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 |
32
| 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 |
43
| 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 |

0 commit comments

Comments
 (0)