-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathCommon.qll
More file actions
71 lines (63 loc) · 1.91 KB
/
Common.qll
File metadata and controls
71 lines (63 loc) · 1.91 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import java
private Stmt getASwitchChild(SwitchStmt s) {
result = s.getAChild()
or
exists(Stmt mid |
mid = getASwitchChild(s) and not mid instanceof SwitchStmt and result = mid.getAChild()
)
}
private predicate blockInSwitch(SwitchStmt s, BasicBlock b) {
b.getFirstNode().getEnclosingStmt() = getASwitchChild(s)
}
private predicate switchCaseControlFlow(SwitchStmt switch, BasicBlock b1, BasicBlock b2) {
blockInSwitch(switch, b1) and
b1.getABBSuccessor() = b2 and
blockInSwitch(switch, b2)
}
predicate switchCaseControlFlowPlus(SwitchStmt switch, BasicBlock b1, BasicBlock b2) {
switchCaseControlFlow(switch, b1, b2)
or
exists(BasicBlock mid |
switchCaseControlFlowPlus(switch, mid, b2) and
switchCaseControlFlow(switch, b1, mid) and
not mid.getFirstNode() = switch.getACase()
)
}
predicate mayDropThroughWithoutComment(SwitchStmt switch, Stmt switchCase) {
switchCase = switch.getACase() and
exists(Stmt other, BasicBlock b1, BasicBlock b2 |
b1.getFirstNode() = switchCase and
b2.getFirstNode() = other and
switchCaseControlFlowPlus(switch, b1, b2) and
other = switch.getACase() and
not fallThroughCommented(other)
)
}
private predicate fallThroughCommented(Stmt case) {
exists(Location loc |
loc = case.getLocation() and
loc.getStartLine() = fallThroughCommentedLine(loc.getFile())
)
}
private int fallThroughCommentedLine(File f) {
exists(Location loc, JavadocText text |
loc.getFile() = f and
text.getLocation() = loc and
text.getText().toLowerCase().regexpMatch(".*falls?[ -]?(through|thru).*") and
result = loc.getStartLine() + 1
)
or
exists(int mid |
mid = fallThroughCommentedLine(f) and
not stmtLine(f) = mid and
mid < max(stmtLine(f)) and
result = mid + 1
)
}
private int stmtLine(File f) {
exists(Stmt s, Location loc |
s.getLocation() = loc and
loc.getFile() = f and
loc.getStartLine() = result
)
}