File tree Expand file tree Collapse file tree 4 files changed +20
-7
lines changed
test/query-tests/variables/DeadStoreOfLocal Expand file tree Collapse file tree 4 files changed +20
-7
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 exists ( SuperCall s |
22+ s .getEnclosingCallable ( ) .getAParameter ( ) .getAVariable ( ) .getAnAccess ( ) = this
23+ |
24+ // a call to 'super' without any arguments will pass on the parameter.
25+ // thus, the parameter is used, and the assignment is not useless.
26+ not exists ( s .getAnArgument ( ) )
27+ ) and
28+ not API:: getTopLevelMember ( "ERB" ) .getInstance ( ) .getAMethodCall ( "result" ) .asExpr ( ) .getScope ( ) =
29+ this .getCfgScope ( ) and
30+ not exists ( RetryStmt r | r .getCfgScope ( ) = this .getCfgScope ( ) ) and
31+ not exists ( MethodCall c |
32+ c .getReceiver ( ) instanceof SelfVariableAccess and
33+ c .getMethodName ( ) = "binding" and
34+ c .getCfgScope ( ) = this .getCfgScope ( )
35+ )
2036 }
2137}
2238
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
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