8000 ruby: remove some FPs from `rb/useless-assignment-to-local` by yoff · Pull Request #19164 · github/codeql · GitHub
[go: up one dir, main page]

Skip to content

ruby: remove some FPs from rb/useless-assignment-to-local #19164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
ruby: add qhelp to rb/useless-assignment-to-local
  • Loading branch information
yoff committed Apr 7, 2025
commit e5fc1b0b001865d7f1ccd0e28e61c79531f97ff8
49 changes: 49 additions & 0 deletions ruby/ql/src/queries/variables/DeadStoreOfLocal.qhelp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>
A value is assigned to a local variable, but either that variable is never read
later on, or its value is always overwritten before being read. This means
that the original assignment has no effect, and could indicate a logic error or
incomplete code.
</p>

</overview>
<recommendation>

<p>
Ensure that you check the control and data flow in the method carefully.
If a value is really not needed, consider omitting the assignment. Be careful,
though: if the right-hand side has a side-effect (like performing a method call),
it is important to keep this to preserve the overall behavior.
</p>

</recommendation>
<example>

<p>
In the following example, the return value of the call to <code>send</code> on line 2
is assigned to the local variable <code>result</code>, but then never used.
</p>

<sample src="examples/DeadStoreOfLocal.rb" />

<p>
Assuming that <code>send</code> returns a status code indicating whether the operation
succeeded or not, the value of <code>result</code> should be checked, perhaps like this:
</p>

<sample src="examples/DeadStoreOfLocalGood.rb" />

</example>
<references>


<li>Wikipedia: <a href="http://en.wikipedia.org/wiki/Dead_store">Dead store</a>.</li>



</references>
</qhelp>
5 changes: 5 additions & 0 deletions ruby/ql/src/queries/variables/examples/DeadStoreOfLocal.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def f(x)
result = send(x)
waitForResponse
return getResponse
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def f(x)
result = send(x)
# check for error
if (result == -1)
raise "Unable to send, check network."
end
waitForResponse
return getResponse
end
0