forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDuplicateSwitchCase.ql
More file actions
33 lines (29 loc) · 854 Bytes
/
DuplicateSwitchCase.ql
File metadata and controls
33 lines (29 loc) · 854 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
/**
* @name Duplicate switch case
* @description If two cases in a switch statement have the same label, the second case
* will never be executed.
* @kind problem
* @problem.severity warning
* @id js/duplicate-switch-case
* @tags maintainability
* correctness
* external/cwe/cwe-561
* @precision very-high
*/
import Clones
/**
* A clone detector for finding structurally identical case labels.
*/
class DuplicateSwitchCase extends StructurallyCompared {
DuplicateSwitchCase() { exists(Case c | this = c.getExpr()) }
override Expr candidate() {
exists(SwitchStmt s, int i, int j |
this = s.getCase(i).getExpr() and
result = s.getCase(j).getExpr() and
i < j
)
}
}
from DuplicateSwitchCase e, Expr f
where e.same(f)
select f, "This case label is a duplicate of $@.", e, e.toString()