forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUninitializedLocal.qhelp
More file actions
36 lines (25 loc) · 1.07 KB
/
UninitializedLocal.qhelp
File metadata and controls
36 lines (25 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>
In Ruby, raw identifiers like <code>x</code> can be both local variable accesses and method calls. It is a local variable access iff it is syntactically preceded by something that binds it (like an assignment).
Consider the following example:
</p>
<sample src="examples/UninitializedLocal.rb" />
<p>
This will generate an alert on the last access to <code>m</code>, where it is not clear that the programmer intended to read from the local variable.
</p>
</overview>
<recommendation>
<p>
Ensure that you check the control and data flow in the method carefully.
Check that the variable reference is spelled correctly, perhaps the variable has been renamed and the reference needs to be updated.
Another possibility is that an exception may be raised before the variable is assigned, in which case the read should be protected by a check for <code>nil</code>.
</p>
</recommendation>
<references>
<li>Wikipedia: <a href="http://en.wikipedia.org/wiki/Dead_store">Dead store</a>.</li>
</references>
</qhelp>