diff --git a/ql/src/codeql_ruby/controlflow/internal/ControlFlowGraphImpl.qll b/ql/src/codeql_ruby/controlflow/internal/ControlFlowGraphImpl.qll index c3e7d79d64d..241fe949329 100644 --- a/ql/src/codeql_ruby/controlflow/internal/ControlFlowGraphImpl.qll +++ b/ql/src/codeql_ruby/controlflow/internal/ControlFlowGraphImpl.qll @@ -353,9 +353,9 @@ module Trees { private class AssignmentTree extends StandardPostOrderTree, AssignExpr { final override ControlFlowTree getChildNode(int i) { - result = this.getRightOperand() and i = 0 + result = this.getLeftOperand() and i = 0 or - result = this.getLeftOperand() and i = 1 + result = this.getRightOperand() and i = 1 } } diff --git a/ql/test/library-tests/controlflow/graph/Cfg.expected b/ql/test/library-tests/controlflow/graph/Cfg.expected index 18ff3d01381..b585b8ac4f0 100644 --- a/ql/test/library-tests/controlflow/graph/Cfg.expected +++ b/ql/test/library-tests/controlflow/graph/Cfg.expected @@ -418,16 +418,16 @@ cfg.rb: #-----| -> bar # 3| bar -#-----| -> 42 +#-----| -> b # 5| ... = ... #-----| -> b # 5| b -#-----| -> ... = ... +#-----| -> 42 # 5| 42 -#-----| -> b +#-----| -> ... = ... # 7| %i(...) #-----| -> b @@ -651,7 +651,7 @@ cfg.rb: #-----| -> ... == ... # 48| call to puts -#-----| -> "a" +#-----| -> chained # 48| "one" #-----| -> call to puts @@ -671,7 +671,7 @@ cfg.rb: # 49| ... > ... #-----| true -> "some" -#-----| false -> "a" +#-----| false -> chained # 49| b #-----| -> 1 @@ -680,16 +680,16 @@ cfg.rb: #-----| -> ... > ... # 49| call to puts -#-----| -> "a" +#-----| -> chained # 49| "some" #-----| -> call to puts # 52| ... = ... -#-----| -> ?\x40 +#-----| -> character # 52| chained -#-----| -> ... = ... +#-----| -> "a" # 52| "a" #-----| -> chained @@ -704,40 +704,40 @@ cfg.rb: #-----| -> #{...} # 52| "string" -#-----| -> chained +#-----| -> ... = ... # 54| ... = ... #-----| -> Silly # 54| character -#-----| -> ... = ... +#-----| -> ?\x40 # 54| ?\x40 -#-----| -> character +#-----| -> ... = ... # 58| Silly #-----| -> Object # 58| Object -#-----| -> 10-2i - -# 59| ... = ... -#-----| -> call to b - -# 59| complex -#-----| -> ... = ... - -# 59| 10-2i #-----| -> complex -# 60| ... = ... -#-----| -> "constant" +# 59| ... = ... +#-----| -> conditional -# 60| conditional +# 59| complex +#-----| -> 10-2i + +# 59| 10-2i #-----| -> ... = ... +# 60| ... = ... +#-----| -> C + +# 60| conditional +#-----| -> call to b + # 60| ... ? ... : ... -#-----| -> conditional +#-----| -> ... = ... # 60| ... < ... #-----| true -> "hello" @@ -756,19 +756,19 @@ cfg.rb: #-----| -> ... ? ... : ... # 61| ... = ... -#-----| -> 1 +#-----| -> x # 61| C -#-----| -> ... = ... +#-----| -> "constant" # 61| "constant" -#-----| -> C +#-----| -> ... = ... # 62| ... = ... #-----| -> pattern # 62| (..., ...) -#-----| -> ... = ... +#-----| -> 1 # 62| x #-----| -> y @@ -783,7 +783,7 @@ cfg.rb: #-----| -> (..., ...) # 62| [...] -#-----| -> x +#-----| -> ... = ... # 62| 1 #-----| -> 2 @@ -801,7 +801,7 @@ cfg.rb: #-----| -> a # 63| pattern -#-----| -> 1 +#-----| -> items # 63| exit pattern @@ -833,10 +833,10 @@ cfg.rb: #-----| -> items # 67| items -#-----| -> ... = ... +#-----| -> 1 # 67| [...] -#-----| -> items +#-----| -> ... = ... # 67| 1 #-----| -> 2 @@ -863,7 +863,7 @@ cfg.rb: #-----| -> "silly" # 69| print -#-----| -> 42 +#-----| -> x # 69| exit print @@ -880,10 +880,10 @@ cfg.rb: #-----| -> x # 74| x -#-----| -> ... = ... +#-----| -> 42 # 74| 42 -#-----| -> x +#-----| -> ... = ... # 75| if ... #-----| -> ; @@ -933,7 +933,7 @@ cfg.rb: #-----| -> "end" # 85| call to puts -#-----| -> x +#-----| -> escape # 85| "end" #-----| -> call to puts @@ -942,10 +942,10 @@ cfg.rb: #-----| -> 1.4 # 88| escape -#-----| -> ... = ... +#-----| -> x # 88| "\u1234#{...}\n" -#-----| -> escape +#-----| -> ... = ... # 88| #{...} #-----| -> "\u1234#{...}\n" @@ -954,7 +954,7 @@ cfg.rb: #-----| -> #{...} # 90| for ... in ... -#-----| -> 42 +#-----| -> $global # 90| x #-----| -> x @@ -998,22 +998,22 @@ cfg.rb: #-----| -> call to puts # 95| ... = ... -#-----| -> "a" +#-----| -> map1 # 95| $global -#-----| -> ... = ... +#-----| -> 42 # 95| 42 -#-----| -> $global - -# 97| ... = ... -#-----| -> map1 - -# 97| map1 #-----| -> ... = ... +# 97| ... = ... +#-----| -> map2 + +# 97| map1 +#-----| -> "a" + # 97| {...} -#-----| -> map1 +#-----| -> ... = ... # 97| "a" #-----| -> "b" @@ -1046,10 +1046,10 @@ cfg.rb: #-----| -> parameters # 98| map2 -#-----| -> ... = ... +#-----| -> map1 # 98| {...} -#-----| -> map2 +#-----| -> ... = ... # 98| **... #-----| -> "x" @@ -1076,7 +1076,7 @@ cfg.rb: #-----| -> value # 101| parameters -#-----| -> "healthy" +#-----| -> type # 101| exit parameters @@ -1115,22 +1115,22 @@ cfg.rb: #-----| -> ...[...] # 106| ... = ... -#-----| -> "food" +#-----| -> table # 106| type -#-----| -> ... = ... +#-----| -> "healthy" # 106| "healthy" -#-----| -> type +#-----| -> ... = ... # 107| ... = ... #-----| -> < ... = ... +#-----| -> "food" # 107| "food" -#-----| -> table +#-----| -> ... = ... # 108| call to puts #-----| -> b @@ -1173,37 +1173,37 @@ cfg.rb: #-----| -> ... > ... # 115| C -#-----| -> 42 - -# 116| ... = ... -#-----| -> 10 - -# 116| @field -#-----| -> ... = ... - -# 116| 42 #-----| -> @field -# 117| ... = ... -#-----| -> -> { ... } +# 116| ... = ... +#-----| -> @@static_field -# 117| @@static_field +# 116| @field +#-----| -> 42 + +# 116| 42 #-----| -> ... = ... +# 117| ... = ... +#-----| -> swap + +# 117| @@static_field +#-----| -> 10 + # 117| 10 -#-----| -> @@static_field +#-----| -> ... = ... # 120| ... = ... #-----| -> M # 120| swap -#-----| -> ... = ... +#-----| -> -> { ... } # 120| enter -> { ... } #-----| -> x # 120| -> { ... } -#-----| -> swap +#-----| -> ... = ... # 120| exit -> { ... } @@ -1229,28 +1229,28 @@ cfg.rb: #-----| -> [...] # 122| M -#-----| -> nil +#-----| -> nothing # 123| ... = ... -#-----| -> 2 +#-----| -> some # 123| nothing -#-----| -> ... = ... +#-----| -> nil # 123| nil -#-----| -> nothing +#-----| -> ... = ... # 124| ... = ... #-----| -> some # 124| some -#-----| -> ... = ... +#-----| -> 2 # 124| 2 -#-----| -> some +#-----| -> ... = ... # 125| ... += ... -#-----| -> 2 +#-----| -> last # 125| some #-----| -> 10 @@ -1259,13 +1259,13 @@ cfg.rb: #-----| -> ... += ... # 126| ... = ... -#-----| -> 0 +#-----| -> range # 126| last -#-----| -> ... = ... +#-----| -> 2 # 126| (...; ...) -#-----| -> last +#-----| -> ... = ... # 126| 2 #-----| -> 4 @@ -1277,13 +1277,13 @@ cfg.rb: #-----| -> (...; ...) # 127| ... = ... -#-----| -> 1 +#-----| -> half # 127| range -#-----| -> ... = ... +#-----| -> 0 # 127| _ .. _ -#-----| -> range +#-----| -> ... = ... # 127| 0 #-----| -> 9 @@ -1292,13 +1292,13 @@ cfg.rb: #-----| -> _ .. _ # 128| ... = ... -#-----| -> range +#-----| -> regex # 128| half -#-----| -> ... = ... +#-----| -> 1 # 128| ... + ... -#-----| -> half +#-----| -> ... = ... # 128| ... / ... #-----| -> 1 @@ -1319,13 +1319,13 @@ cfg.rb: #-----| -> ... / ... # 129| ... = ... -#-----| -> 5 +#-----| -> Constant # 129| regex -#-----| -> ... = ... +#-----| -> range # 129| /hello\s+[#{...}]/ -#-----| -> regex +#-----| -> ... = ... # 129| #{...} #-----| -> /hello\s+[#{...}]/ @@ -1337,10 +1337,10 @@ cfg.rb: #-----| -> EmptyClass # 130| Constant -#-----| -> ... = ... +#-----| -> 5 # 130| 5 -#-----| -> Constant +#-----| -> ... = ... # 133| EmptyClass #-----| -> EmptyModule @@ -1353,7 +1353,7 @@ cfg.rb: # 136| ... / ... #-----| raise -> "div by zero" -#-----| -> 1 +#-----| -> init # 136| 1 #-----| -> 0 @@ -1362,7 +1362,7 @@ cfg.rb: #-----| -> ... / ... # 136| call to puts -#-----| -> 1 +#-----| -> init # 136| "div by zero" #-----| -> call to puts @@ -1371,7 +1371,7 @@ cfg.rb: #-----| -> M # 138| (..., ...) -#-----| -> ... = ... +#-----| -> 1 # 138| init #-----| -> last @@ -1386,7 +1386,7 @@ cfg.rb: #-----| -> 3 # 138| 3 -#-----| -> init +#-----| -> ... = ... # 140| M #-----| -> Constant @@ -1419,7 +1419,7 @@ cfg.rb: #-----| -> "singleton" # 145| print -#-----| -> Silly +#-----| -> silly # 145| exit print @@ -1445,10 +1445,10 @@ cfg.rb: #-----| -> silly # 151| silly -#-----| -> ... = ... +#-----| -> Silly # 151| call to new -#-----| -> silly +#-----| -> ... = ... # 151| Silly #-----| -> call to new @@ -1494,7 +1494,7 @@ cfg.rb: #-----| -> exit two_parameters (normal) # 158| call to two_parameters -#-----| -> call to __FILE__ +#-----| -> scriptfile # 158| *... #-----| -> call to two_parameters @@ -1509,13 +1509,13 @@ cfg.rb: #-----| -> [...] # 160| ... = ... -#-----| -> :hello +#-----| -> symbol # 160| scriptfile -#-----| -> ... = ... +#-----| -> call to __FILE__ # 160| `cat "#{...}"` -#-----| -> scriptfile +#-----| -> ... = ... # 160| #{...} #-----| -> `cat "#{...}"` @@ -1524,22 +1524,22 @@ cfg.rb: #-----| -> #{...} # 162| ... = ... -#-----| -> 12 +#-----| -> delimited_symbol # 162| symbol -#-----| -> ... = ... +#-----| -> :hello # 162| :hello -#-----| -> symbol - -# 164| ... = ... -#-----| -> true - -# 164| delimited_symbol #-----| -> ... = ... +# 164| ... = ... +#-----| -> x + +# 164| delimited_symbol +#-----| -> 12 + # 164| :"goodbye-#{...}" -#-----| -> delimited_symbol +#-----| -> ... = ... # 164| #{...} #-----| -> :"goodbye-#{...}" @@ -1554,23 +1554,23 @@ cfg.rb: #-----| -> ... + ... # 166| ... = ... -#-----| -> true +#-----| -> x # 166| x -#-----| -> ... = ... +#-----| -> true # 166| true -#-----| -> x - -# 167| ... = ... -#-----| -> 42 - -# 167| x #-----| -> ... = ... -# 167| ! ... +# 167| ... = ... #-----| -> x +# 167| x +#-----| -> true + +# 167| ! ... +#-----| -> ... = ... + # 167| true #-----| -> ! ... @@ -1578,10 +1578,10 @@ cfg.rb: #-----| -> undef ... # 168| x -#-----| -> ... = ... +#-----| -> 42 # 168| - ... -#-----| -> x +#-----| -> ... = ... # 168| 42 #-----| -> - ... @@ -1637,7 +1637,7 @@ cfg.rb: #-----| -> ... == ... # 176| until ... -#-----| -> 0 +#-----| -> i # 176| ... > ... #-----| true -> until ... @@ -1668,16 +1668,16 @@ cfg.rb: #-----| -> i # 178| i -#-----| -> ... = ... +#-----| -> 0 # 178| 0 -#-----| -> i +#-----| -> ... = ... # 179| (...; ...) #-----| -> i # 179| ... until ... -#-----| -> 0 +#-----| -> x # 179| call to puts #-----| -> i @@ -1708,10 +1708,10 @@ cfg.rb: #-----| -> x # 181| x -#-----| -> ... = ... +#-----| -> 0 # 181| 0 -#-----| -> x +#-----| -> ... = ... # 182| while ... #-----| -> i @@ -2125,10 +2125,10 @@ ifs.rb: #-----| -> x # 20| x -#-----| -> ... = ... +#-----| -> x # 20| - ... -#-----| -> x +#-----| -> ... = ... # 20| x #-----| -> - ... @@ -2150,10 +2150,10 @@ ifs.rb: #-----| -> if ... # 22| x -#-----| -> ... = ... +#-----| -> x # 22| ... - ... -#-----| -> x +#-----| -> ... = ... # 22| x #-----| -> 1