File tree Expand file tree Collapse file tree 4 files changed +14
-8
lines changed
test/query-tests/variables/DeadStoreOfLocal Expand file tree Collapse file tree 4 files changed +14
-8
lines changed Original file line number Diff line number Diff line change 1212
1313import codeql.ruby.AST
1414import codeql.ruby.dataflow.SSA
15+ import codeql.ruby.ApiGraphs
1516
1617class RelevantLocalVariableWriteAccess extends LocalVariableWriteAccess {
1718 RelevantLocalVariableWriteAccess ( ) {
1819 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+ )
2029 }
2130}
2231
Original file line number Diff line number Diff line change 11| 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
1111 raise "error"
1212 end
1313 rescue
14- x = 2 #$ SPURIOUS: Alert
14+ x = 2 # OK - the retry will allow a later read
1515 retry
1616 end
1717 return 42
1818end
1919
2020def test_binding
21- x = 4 #$ SPURIOUS: Alert
21+ x = 4 # OK - the binding collects the value of x
2222 return binding
2323end
2424
@@ -30,7 +30,7 @@ def m(x)
3030
3131class Sub < Sup
3232 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``
3434 super
3535 end
3636end
Original file line number Diff line number Diff line change 66 \_ \_ ENCODING\_ \_ is <%= \_ \_ ENCODING\_ \_ %>.
77 x is <%= x %>.
88EOF
9- x = 5 #$ SPURIOUS: Alert
9+ x = 5 # OK - the template can see the value of x
1010puts template . result
You can’t perform that action at this time.
0 commit comments