-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathDeadStoreOfLocal.qhelp
More file actions
35 lines (26 loc) · 1.22 KB
/
DeadStoreOfLocal.qhelp
File metadata and controls
35 lines (26 loc) · 1.22 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
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>A value is assigned to a local variable, but whenever the variable is subsequently
read, there has been at least one other assignment to that variable. This means
that the original assignment is suspect, because the state of the local variable that
it creates is never used.</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 value assigned to <code>result</code> on line 5 is always
overwritten (line 6) before being read (line 7). This is a strong indicator that
there is something wrong. By examining the code, we can see that the
loop in lines 3-5 seems to be left over from an old way of storing the list of
persons, and line 6 represents the new (and better-performing) way. Consequently,
we can delete lines 3-5 while preserving behavior.</p>
<sample src="DeadStoreOfLocal.java" />
</example>
</qhelp>