mirror of
https://github.com/github/codeql.git
synced 2026-04-22 07:15:15 +02:00
Account for pattern-cases in more places
This commit is contained in:
@@ -73,13 +73,15 @@ class MetricCallable extends Callable {
|
||||
// so there should be a branching point for each non-default switch
|
||||
// case (ignoring those that just fall through to the next case).
|
||||
private predicate branchingSwitchCase(ConstCase sc) {
|
||||
not sc.(ControlFlowNode).getASuccessor() instanceof ConstCase and
|
||||
not sc.(ControlFlowNode).getASuccessor() instanceof DefaultCase and
|
||||
not sc.(ControlFlowNode).getASuccessor() instanceof SwitchCase and
|
||||
not defaultFallThrough(sc)
|
||||
}
|
||||
|
||||
private predicate defaultFallThrough(ConstCase sc) {
|
||||
exists(DefaultCase default | default.(ControlFlowNode).getASuccessor() = sc) or
|
||||
exists(SwitchCase default | default.hasDefaultLabel() |
|
||||
default.(ControlFlowNode).getASuccessor() = sc
|
||||
)
|
||||
or
|
||||
defaultFallThrough(sc.(ControlFlowNode).getAPredecessor())
|
||||
}
|
||||
|
||||
@@ -90,6 +92,7 @@ private predicate branchingStmt(Stmt stmt) {
|
||||
stmt instanceof DoStmt or
|
||||
stmt instanceof ForStmt or
|
||||
stmt instanceof EnhancedForStmt or
|
||||
stmt instanceof PatternCase or
|
||||
branchingSwitchCase(stmt) or
|
||||
stmt instanceof CatchClause
|
||||
}
|
||||
|
||||
@@ -17,8 +17,7 @@ import Common
|
||||
from SwitchStmt s, Stmt c
|
||||
where
|
||||
c = s.getACase() and
|
||||
not c.(ControlFlowNode).getASuccessor() instanceof ConstCase and
|
||||
not c.(ControlFlowNode).getASuccessor() instanceof DefaultCase and
|
||||
not c.(ControlFlowNode).getASuccessor() instanceof SwitchCase and
|
||||
not s.(Annotatable).suppressesWarningsAbout("fallthrough") and
|
||||
mayDropThroughWithoutComment(s, c)
|
||||
select c,
|
||||
|
||||
Reference in New Issue
Block a user