-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathRedundantExpr.qhelp
More file actions
36 lines (32 loc) · 977 Bytes
/
RedundantExpr.qhelp
File metadata and controls
36 lines (32 loc) · 977 Bytes
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>
Many arithmetic or logical operators yield a trivial result when applied to
identical operands: for instance, <code>x-x</code> is zero if <code>x</code>
is a number, and <code>NaN</code> otherwise; <code>x&x</code> is always
equal to <code>x</code>. Code like this is often the result of a typo, such as
misspelling a variable name.
</p>
</overview>
<recommendation>
<p>
Carefully inspect the expression to ensure it is not a symptom of a bug.
</p>
</recommendation>
<example>
<p>
In the example below, the function <code>avg</code> is intended to compute the
average of two numbers <code>x</code> and <code>y</code>. However, the programmer
accidentally used <code>x</code> twice, so the function just returns
<code>x</code>:
</p>
<sample src="RedundantExpr.go" />
<p>
This problem can be fixed by correcting the typo:
</p>
<sample src="RedundantExprGood.go" />
</example>
</qhelp>