Skip to content

Commit 3dc517c

Browse files
committed
Rust: Handle absence of else branch in if expression in CFG
1 parent 67a06cb commit 3dc517c

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

rust/ql/lib/codeql/rust/controlflow/internal/ControlFlowGraphImpl.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,14 @@ class IfExprTree extends PostOrderTree instanceof IfExpr {
9797
}
9898

9999
override predicate succ(AstNode pred, AstNode succ, Completion c) {
100-
// Edges from the condition to each branch
100+
// Edges from the condition to the branches
101101
last(super.getCondition(), pred, c) and
102102
(
103103
first(super.getThen(), succ) and c.(BooleanCompletion).getValue() = true
104104
or
105105
first(super.getElse(), succ) and c.(BooleanCompletion).getValue() = false
106+
or
107+
not super.hasElse() and succ = this and c.(BooleanCompletion).getValue() = false
106108
)
107109
or
108110
// An edge from the then branch to the last node

0 commit comments

Comments
 (0)