Skip to content

Commit 3b86205

Browse files
committed
RULE-15-3 WIP
1 parent 4599a73 commit 3b86205

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

c/misra/src/rules/RULE-15-3/GotoLabelBlockCondition.ql

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

18+
int statementDepth(Stmt statement) {
19+
statement.getParent() = statement.getEnclosingFunction().getBlock() and result = 1
20+
or
21+
statementDepth(statement.getParent()) + 1 = result
22+
}
23+
24+
predicate test(GotoStmt goto, Stmt target, int m, int n) {
25+
statementDepth(goto) = m and target = goto.getTarget() and statementDepth(target) = n
26+
}
27+
1828
from GotoStmt goto
1929
where
2030
not isExcluded(goto, Statements2Package::gotoLabelBlockConditionQuery()) and
@@ -33,5 +43,5 @@ where
3343
) and
3444
goto.getTarget().getLocation().getStartLine() > switch.getLocation().getStartLine()
3545
)
36-
select goto, "The $@ statement and its $@ are not declared or enclosed in the same block.", goto,
37-
"goto", goto.getTarget(), "label"
46+
select goto, "The $@ statement and its $@ are not declared or enclosed in the same block. test",
47+
goto, "goto", goto.getTarget(), "label"

0 commit comments

Comments
 (0)