forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
471 lines (411 loc) · 6.72 KB
/
test.py
File metadata and controls
471 lines (411 loc) · 6.72 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
def split1(cond):
if cond:
pass
if cond:
pass
def dont_split1(cond):
if cond:
pass
cond = f()
if cond:
pass
def dont_split2(cond):
if cond:
pass
for cond in seq: pass
if cond:
pass
def split2():
try:
call()
x = True
except:
x = False
if x:
pass
def unclear_split3():
try: # May be arguably better to split here.
call()
x = True
except:
x = False
if cond: # Currently split here
x = False
if x:
pass
def split4(x):
if x is None:
x = not_none()
c if b else c
return x
def split_carefully_5(x):
if x is None:
x = not_none()
if x:
pass
return x
def dont_split_globals():
if cond:
pass
call_could_alter_any_global()
if cond:
pass
def limit_splitting1(a,b,c,d):
if a is None: a = "a"
if b is None: b = "b"
if c is None: c = "c"
if d is None: d = "d"
pass
def limit_splitting2(a,b,c,d):
if a:
pass
if b:
pass
if c:
pass
if d:
pass
#These should be pruned
if a:
a1
if b:
b1
#But not these
if c:
c1
if d:
d1
def split_on_numbers():
try:
call()
x = -1
except:
x = 0
if x:
pass
def split_try_except_else():
try:
call()
except:
x = 0
else:
x = 1
if x:
pass
#Example taken from logging module
#Splitting should allow us to deduce that module2 is defined at point of use
def logging():
try:
import module1
import module2
except ImportError:
module1 = None
if module1:
inst = module2.Class()
#Handle 'not' as well.
def split5():
try:
call()
x = True
except:
x = False
if not x:
pass
def split6():
try:
call()
x = True
except:
x = False
if not not x:
pass
def split7():
try:
call()
x = not True
except:
x = not False
if x:
pass
def split8(cond):
if cond:
t = True
else:
t = False
if not cond:
if t:
pass
def split9(var):
if var is None:
a1
else:
a2
if var is not None:
b1
else:
b2
def split10(var):
if var:
a1
else:
a2
if var is not None:
b1
else:
b2
def split11(var):
if var is None:
a1
else:
a2
if var:
b1
else:
b2
def dont_split_on_unrelated_variables(var1, var2):
if var1 is None:
a1
else:
a2
if var2 is not None:
b1
else:
b2
def split12():
try:
call()
x = None
except:
import x
if x:
pass
def split13():
var = cond()
if var:
a1
else:
a2
try:
b1
finally:
if var:
a3
def split14():
flag = False
try:
x = something()
except Exception:
99
flag = True
if not flag:
#Should be split here
pass
def split15(var):
if var:
other = 0
if not var or other.attr: #other looks like it might be undefined, but it is defined.
pass
def split16():
x = True
if cond:
x = None
if x:
use(x)
def dont_split_on_different_ssa(var):
if var:
a1
else:
a2
var = func()
if var is not None:
b1
else:
b2
def split17(var):
#Should only be split once
if var:
a1
else:
a2
if not var:
b1
else:
b2
if var:
c1
else:
c2
if var:
d1
else:
d2
if var:
e1
else:
e2
def split18(var):
#Should only be split once
if var:
a1
else:
a2
if var is not None: #Distinguishes between False and None
b1
else:
b2
if var is None:
c1
else:
c2
if var:
d1
else:
d2
if var:
e1
else:
e2
def split_on_boolean_only(x):
if x:
a1
else:
a2
if x is not None:
b1
else:
b2
if x:
c1
else:
c2
def split_on_none_aswell(x):
if x:
a1
else:
a2
if x is not None:
b1
else:
b2
if x is None:
c1
else:
c2
def split_on_or_defn(var):
if var:
obj = thing()
if not var or obj.attr: # obj is defined if reached
x
def split_on_exception():
flag = False
try:
x = do_something()
except Exception:
flag = True
if not flag:
x # x is defined here
def partially_useful_split(cond):
if cond:
x = None
else:
x = something_or_none()
other_stuff()
if x:
a1
else:
a2
def dont_split_not_useful(cond, y):
if cond:
x = None
else:
x = something_or_none()
other_stuff()
if y:
a1
else:
a2
#Splittings with boolean expressions:
def f(x,y):
if x and y:
raise
if not (x or y):
raise
pass
def g(x,y):
if x and y:
raise
if x or y:
# Either x or y is true here (exclusive).
here
end
def h(x, y):
if (
(x and
not y) or
(x and
y.meth())
):
pass
def j(a, b):
if a or b:
if a:
here
else:
there
def split_on_strings():
try:
might_fail()
x = "yes+"
except:
x = "no"
#We want to split here, even though we can't (easily) prune
if x == "no":
pass
pass
def scipy_stylee(x):
assert x in ("a", "b", "c")
if x == "a":
pass
elif x == "b":
pass
elif x == "c":
pass
else:
#unreachable
pass
def odasa_6674(x):
valid = True
if dont_understand_this():
try:
may_raise()
score = 0
except KeyError:
valid = False
if not valid:
raise ValueError()
else:
score = 1
return score
def odasa_6625(k):
value = "hi"
if k.endswith('_min') or k.endswith('_max'):
value = 0
if k == 'tags':
return value + " there"
def avoid_redundant_split(a):
if a: # Should split here
x = unknown_thing()
else:
x = None
if x: # but not here,
pass
if x: # or here, because
pass
other_stuff()
try: # we want to split here
import foo
var = True
except:
var = False
if var:
foo.bar()