Skip to content

Commit a41eea4

Browse files
authored
Merge pull request #95 from github/hvitved/cfg/not-bug
CFG: Fix bug in `LogicalNotTree`
2 parents 03d407e + 34fe416 commit a41eea4

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

ql/src/codeql_ruby/controlflow/internal/ControlFlowGraphImpl.qll

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -782,12 +782,8 @@ module Trees {
782782

783783
final override predicate succ(AstNode pred, AstNode succ, Completion c) {
784784
succ = this and
785-
(
786-
last(operand, pred, c.(BooleanCompletion).getDual())
787-
or
788-
last(operand, pred, c) and
789-
c instanceof SimpleCompletion
790-
)
785+
last(operand, pred, c) and
786+
c instanceof NormalCompletion
791787
}
792788
}
793789

ql/test/library-tests/controlflow/graph/Cfg.expected

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ ifs.rb:
103103
# 36| enter conditional_method_def
104104
#-----| -> puts
105105

106+
# 40| enter constant_condition
107+
#-----| -> true
108+
106109
loops.rb:
107110
# 1| enter top-level
108111
#-----| -> m1
@@ -2440,7 +2443,7 @@ ifs.rb:
24402443
#-----| -> If
24412444

24422445
# 36| UnlessModifier
2443-
#-----| -> exit top-level (normal)
2446+
#-----| -> constant_condition
24442447

24452448
# 36| Method
24462449
#-----| -> UnlessModifier
@@ -2467,6 +2470,21 @@ ifs.rb:
24672470
# 38| 2
24682471
#-----| -> Binary
24692472

2473+
# 40| Method
2474+
#-----| -> exit top-level (normal)
2475+
2476+
# 40| constant_condition
2477+
#-----| -> Method
2478+
2479+
# 41| If
2480+
#-----| -> exit constant_condition (normal)
2481+
2482+
# 41| [false] Unary
2483+
#-----| false -> If
2484+
2485+
# 41| true
2486+
#-----| true -> [false] Unary
2487+
24702488
loops.rb:
24712489
# 1| Method
24722490
#-----| -> m2
@@ -3771,6 +3789,8 @@ ifs.rb:
37713789

37723790
# 36| exit conditional_method_def
37733791

3792+
# 40| exit constant_condition
3793+
37743794
loops.rb:
37753795
# 1| exit top-level
37763796

@@ -3926,6 +3946,9 @@ ifs.rb:
39263946
# 36| exit conditional_method_def (normal)
39273947
#-----| -> exit conditional_method_def
39283948

3949+
# 40| exit constant_condition (normal)
3950+
#-----| -> exit constant_condition
3951+
39293952
loops.rb:
39303953
# 1| exit top-level (normal)
39313954
#-----| -> exit top-level

ql/test/library-tests/controlflow/graph/ifs.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,9 @@ def m5 (b1, b2, b3, b4, b5)
3636
def conditional_method_def()
3737
puts "bla"
3838
end unless 1 == 2
39+
40+
def constant_condition()
41+
if !true
42+
puts "Impossible"
43+
end
44+
end

0 commit comments

Comments
 (0)