|
1 | 1 | import ql |
2 | 2 |
|
3 | 3 | predicate test1(int a) { |
4 | | - a = 1 or // BAD |
5 | | - a = 2 or |
6 | | - a = 3 or |
7 | | - a = 4 |
| 4 | + a = 1 or // BAD |
| 5 | + a = 2 or |
| 6 | + a = 3 or |
| 7 | + a = 4 |
8 | 8 | } |
9 | 9 |
|
10 | 10 | predicate test2(int a) { |
11 | | - a = [1, 2, 3, 4] // GOOD |
| 11 | + a = [1, 2, 3, 4] // GOOD |
12 | 12 | } |
13 | 13 |
|
14 | 14 | predicate test3(int a) { |
15 | | - a = 1 and // GOOD (for the purposes of this query) |
16 | | - a = 2 and |
17 | | - a = 3 and |
18 | | - a = 4 |
| 15 | + a = 1 and // GOOD (for the purposes of this query) |
| 16 | + a = 2 and |
| 17 | + a = 3 and |
| 18 | + a = 4 |
19 | 19 | } |
20 | 20 |
|
21 | | -bindingset[a] predicate test4(int a) { |
22 | | - a < 1 or // GOOD (for the purposes of this query) |
23 | | - a = 2 or |
24 | | - a >= 3 or |
25 | | - a > 4 |
| 21 | +bindingset[a] |
| 22 | +predicate test4(int a) { |
| 23 | + a < 1 or // GOOD (for the purposes of this query) |
| 24 | + a = 2 or |
| 25 | + a >= 3 or |
| 26 | + a > 4 |
26 | 27 | } |
27 | 28 |
|
28 | 29 | predicate test5() { |
29 | | - test1(1) or // BAD |
30 | | - test1(2) or |
31 | | - test1(3) or |
32 | | - test1(4) |
| 30 | + test1(1) or // BAD |
| 31 | + test1(2) or |
| 32 | + test1(3) or |
| 33 | + test1(4) |
33 | 34 | } |
34 | 35 |
|
35 | 36 | predicate test6() { |
36 | | - test1(1) or // GOOD |
37 | | - test2(2) or |
38 | | - test3(3) or |
39 | | - test4(4) |
| 37 | + test1(1) or // GOOD |
| 38 | + test2(2) or |
| 39 | + test3(3) or |
| 40 | + test4(4) |
40 | 41 | } |
41 | 42 |
|
42 | 43 | int test7() { |
43 | | - 1 = result or // BAD |
44 | | - 2 = result or |
45 | | - 3 = result or |
46 | | - 4 = result |
| 44 | + 1 = result or // BAD |
| 45 | + 2 = result or |
| 46 | + 3 = result or |
| 47 | + 4 = result |
47 | 48 | } |
48 | 49 |
|
49 | 50 | predicate test8() { |
50 | | - test7() = 1 or // BAD [NOT DETECTED] |
51 | | - test7() = 2 or |
52 | | - test7() = 3 or |
53 | | - test7() = 4 |
| 51 | + test7() = 1 or // BAD [NOT DETECTED] |
| 52 | + test7() = 2 or |
| 53 | + test7() = 3 or |
| 54 | + test7() = 4 |
54 | 55 | } |
55 | 56 |
|
56 | | -class MyTest8Class extends int |
57 | | -{ |
58 | | - string s; |
59 | | - |
60 | | - MyTest8Class() { |
61 | | - ( |
62 | | - this = 1 or // BAD |
63 | | - this = 2 or |
64 | | - this = 3 or |
65 | | - this = 4 |
66 | | - ) and ( |
67 | | - s = "1" or // BAD |
68 | | - s = "2" or |
69 | | - s = "3" or |
70 | | - s = "4" |
71 | | - ) and exists(float f | |
72 | | - f = 1.0 or // BAD |
73 | | - f = 1.5 or |
74 | | - f = 2.0 or |
75 | | - f = 2.5 |
76 | | - ) |
77 | | - } |
78 | | - |
79 | | - predicate is(int x) { |
80 | | - x = this |
81 | | - } |
82 | | - |
83 | | - int get() { |
84 | | - result = this |
85 | | - } |
| 57 | +class MyTest8Class extends int { |
| 58 | + string s; |
| 59 | + |
| 60 | + MyTest8Class() { |
| 61 | + ( |
| 62 | + this = 1 or // BAD |
| 63 | + this = 2 or |
| 64 | + this = 3 or |
| 65 | + this = 4 |
| 66 | + ) and |
| 67 | + ( |
| 68 | + s = "1" or // BAD |
| 69 | + s = "2" or |
| 70 | + s = "3" or |
| 71 | + s = "4" |
| 72 | + ) and |
| 73 | + exists(float f | |
| 74 | + f = 1.0 or // BAD |
| 75 | + f = 1.5 or |
| 76 | + f = 2.0 or |
| 77 | + f = 2.5 |
| 78 | + ) |
| 79 | + } |
| 80 | + |
| 81 | + predicate is(int x) { x = this } |
| 82 | + |
| 83 | + int get() { result = this } |
86 | 84 | } |
87 | 85 |
|
88 | 86 | predicate test9(MyTest8Class c) { |
89 | | - c.is(1) or // BAD |
90 | | - c.is(2) or |
91 | | - c.is(3) or |
92 | | - c.is(4) |
| 87 | + c.is(1) or // BAD |
| 88 | + c.is(2) or |
| 89 | + c.is(3) or |
| 90 | + c.is(4) |
93 | 91 | } |
94 | 92 |
|
95 | 93 | predicate test10(MyTest8Class c) { |
96 | | - c.get() = 1 or // BAD [NOT DETECTED] |
97 | | - c.get() = 2 or |
98 | | - c.get() = 3 or |
99 | | - c.get() = 4 |
| 94 | + c.get() = 1 or // BAD [NOT DETECTED] |
| 95 | + c.get() = 2 or |
| 96 | + c.get() = 3 or |
| 97 | + c.get() = 4 |
100 | 98 | } |
101 | 99 |
|
102 | | -bindingset[a, b, c, d] predicate test11(int a, int b, int c, int d) { |
103 | | - a = 1 or // GOOD |
104 | | - b = 2 or |
105 | | - c = 3 or |
106 | | - d = 4 |
| 100 | +bindingset[a, b, c, d] |
| 101 | +predicate test11(int a, int b, int c, int d) { |
| 102 | + a = 1 or // GOOD |
| 103 | + b = 2 or |
| 104 | + c = 3 or |
| 105 | + d = 4 |
107 | 106 | } |
108 | 107 |
|
109 | | -bindingset[a, b] predicate test12(int a, int b) { |
110 | | - a = 1 or // BAD [NOT DETECTED] |
111 | | - a = 2 or |
112 | | - a = 3 or |
113 | | - a = 4 or |
114 | | - b = 0 |
| 108 | +bindingset[a, b] |
| 109 | +predicate test12(int a, int b) { |
| 110 | + a = 1 or // BAD [NOT DETECTED] |
| 111 | + a = 2 or |
| 112 | + a = 3 or |
| 113 | + a = 4 or |
| 114 | + b = 0 |
115 | 115 | } |
116 | 116 |
|
117 | 117 | predicate test13(int a, int b) { |
118 | | - (a = 1 and b = 1) or // GOOD |
119 | | - (a = 2 and b = 4) or |
120 | | - (a = 3 and b = 9) or |
121 | | - (a = 4 and b = 16) |
| 118 | + a = 1 and b = 1 // GOOD |
| 119 | + or |
| 120 | + a = 2 and b = 4 |
| 121 | + or |
| 122 | + a = 3 and b = 9 |
| 123 | + or |
| 124 | + a = 4 and b = 16 |
122 | 125 | } |
123 | 126 |
|
124 | | -from int a |
125 | | -where |
126 | | - a = 1 or ((a = 2 or a = 3) or a = 4) // BAD |
127 | | -select a |
| 127 | +predicate test14(int a) { |
| 128 | + a = 1 // BAD |
| 129 | + or |
| 130 | + ( |
| 131 | + (a = 2 or a = 3) |
| 132 | + or |
| 133 | + a = 4 |
| 134 | + ) |
| 135 | +} |
0 commit comments