File tree 4 files changed +14
-8
lines changed
test/query-tests/variables/DeadStoreOfLocal
4 files changed +14
-8
lines changed Original file line number Diff line number Diff line change 12
12
13
13
import codeql.ruby.AST
14
14
import codeql.ruby.dataflow.SSA
15
+ import codeql.ruby.ApiGraphs
15
16
16
17
class RelevantLocalVariableWriteAccess extends LocalVariableWriteAccess {
17
18
RelevantLocalVariableWriteAccess ( ) {
18
19
not this .getVariable ( ) .getName ( ) .charAt ( 0 ) = "_" and
19
- not this = any ( Parameter p ) .getAVariable ( ) .getDefiningAccess ( )
20
+ not this = any ( Parameter p ) .getAVariable ( ) .getDefiningAccess ( ) and
21
+ not API:: getTopLevelMember ( "ERB" ) .getInstance ( ) .getAMethodCall ( "result" ) .asExpr ( ) .getScope ( ) =
22
+ this .getCfgScope ( ) and
23
+ not exists ( RetryStmt r | r .getCfgScope ( ) = this .getCfgScope ( ) ) and
24
+ not exists ( MethodCall c |
25
+ c .getReceiver ( ) instanceof SelfVariableAccess and
26
+ c .getMethodName ( ) = "binding" and
27
+ c .getCfgScope ( ) = this .getCfgScope ( )
28
+ )
20
29
}
21
30
}
22
31
Original file line number Diff line number Diff line change 1
1
| DeadStoreOfLocal.rb:2:5:2:5 | y | This assignment to $@ is useless, since its value is never read. | DeadStoreOfLocal.rb:2:5:2:5 | y | y |
2
- | DeadStoreOfLocal.rb:14:9:14:9 | x | This assignment to $@ is useless, since its value is never read. | DeadStoreOfLocal.rb:8:5:8:5 | x | x |
3
- | DeadStoreOfLocal.rb:21:5:21:5 | x | This assignment to $@ is useless, since its value is never read. | DeadStoreOfLocal.rb:21:5:21:5 | x | x |
4
- | TestTemplate.rb:9:1:9:1 | x | This assignment to $@ is useless, since its value is never read. | TestTemplate.rb:9:1:9:1 | x | x |
Original file line number Diff line number Diff line change @@ -11,14 +11,14 @@ def test_retry
11
11
raise "error"
12
12
end
13
13
rescue
14
- x = 2 #$ SPURIOUS: Alert
14
+ x = 2 # OK - the retry will allow a later read
15
15
retry
16
16
end
17
17
return 42
18
18
end
19
19
20
20
def test_binding
21
- x = 4 #$ SPURIOUS: Alert
21
+ x = 4 # OK - the binding collects the value of x
22
22
return binding
23
23
end
24
24
@@ -30,7 +30,7 @@ def m(x)
30
30
31
31
class Sub < Sup
32
32
def m ( y )
33
- y = 3 # OK - the call to `super` sees the value of y
33
+ y = 3 # OK - the call to `super` sees the value of `y``
34
34
super
35
35
end
36
36
end
Original file line number Diff line number Diff line change 6
6
\_ \_ ENCODING\_ \_ is <%= \_ \_ ENCODING\_ \_ %>.
7
7
x is <%= x %>.
8
8
EOF
9
- x = 5 #$ SPURIOUS: Alert
9
+ x = 5 # OK - the template can see the value of x
10
10
puts template . result
You can’t perform that action at this time.
0 commit comments