mirror of
https://github.com/github/codeql.git
synced 2026-02-20 08:53:49 +01:00
Add DeadStoreOfLocal.ql query
This commit is contained in:
28
ql/src/queries/variables/DeadStoreOfLocal.ql
Normal file
28
ql/src/queries/variables/DeadStoreOfLocal.ql
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* @name Useless assignment to local variable
|
||||
* @description An assignment to a local variable that is not used later on, or whose value is always
|
||||
* overwritten, has no effect.
|
||||
* @kind problem
|
||||
* @problem.severity warning
|
||||
* @id rb/useless-assignment-to-local
|
||||
* @tags maintainability
|
||||
* external/cwe/cwe-563
|
||||
* @precision low
|
||||
*/
|
||||
|
||||
import ruby
|
||||
import codeql_ruby.dataflow.SSA
|
||||
|
||||
class RelevantLocalVariableWriteAccess extends LocalVariableWriteAccess {
|
||||
RelevantLocalVariableWriteAccess() {
|
||||
not this.getVariable().getName().charAt(0) = "_" and
|
||||
not this = any(Parameter p).getAVariable().getDefiningAccess()
|
||||
}
|
||||
}
|
||||
|
||||
from RelevantLocalVariableWriteAccess write, LocalVariable v
|
||||
where
|
||||
v = write.getVariable() and
|
||||
exists(write.getAControlFlowNode()) and
|
||||
not exists(Ssa::WriteDefinition def | def.getWriteAccess() = write)
|
||||
select write, "This assignment to $@ is useless, since its value is never read.", v, v.getName()
|
||||
Reference in New Issue
Block a user