-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathCompareIdenticalValues.ql
More file actions
29 lines (27 loc) · 1.03 KB
/
CompareIdenticalValues.ql
File metadata and controls
29 lines (27 loc) · 1.03 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
/**
* @name Comparison of identical values
* @description If the same expression occurs on both sides of a comparison
* operator, the operator is redundant, and probably indicates a mistake.
* @kind problem
* @problem.severity warning
* @id go/comparison-of-identical-expressions
* @tags quality
* reliability
* correctness
* external/cwe/cwe-570
* external/cwe/cwe-571
* @precision very-high
*/
import go
from ComparisonExpr cmp, Expr l
where
l = cmp.getLeftOperand() and
l.getGlobalValueNumber() = cmp.getRightOperand().getGlobalValueNumber() and
// allow floats, where self-comparison may be used for NaN checks
not l.getType().getUnderlyingType() instanceof FloatType and
// allow comparisons of symbolic constants to literal constants; these are often feature flags
not exists(DeclaredConstant decl |
cmp.getAnOperand() = decl.getAReference() and
cmp.getAnOperand() instanceof BasicLit
)
select cmp, "This expression compares an $@ to itself.", cmp.getLeftOperand(), "expression"