Skip to content

Commit 104cf80

Browse files
committed
Fix the foddy infinite loop
1 parent 153501f commit 104cf80

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

example/november_2017_evaluation/infinite_loop/foddy.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,11 @@ def recommended():
88
if is_google_auth():
99
location = get_location(http_auth)
1010

11+
1112
def get_location(http_auth):
1213
for i in range(len(events_result['items'])):
1314
example = events_result['items'][i]['start']
1415
if 'dateTime' in example.keys():
1516
index_of_valid_event = i
1617
break
17-
if 'location' in events_result['items'][index_of_valid_event].keys():
18-
location = events_result['items'][index_of_valid_event]['location']
19-
else:
20-
location = 'unspecified'
21-
return location
18+
return 5

pyt/stmt_visitor.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,11 @@ def assignment_call_node(self, left_hand_label, ast_node):
423423
self.undecided = True # Used for handling functions in assignments
424424

425425
call = self.visit(ast_node.value)
426-
call_label = call.left_hand_side
426+
try:
427+
call_label = call.left_hand_side
428+
except AttributeError:
429+
print('Assigning from a void function is invalid Python')
430+
exit(0)
427431

428432
if isinstance(call, BBorBInode):
429433
# Necessary to know e.g.

pyt/stmt_visitor_helper.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import ast
2+
import random
23
from collections import namedtuple
34

45
from .node_types import (
@@ -101,16 +102,24 @@ def get_first_node(
101102
node,
102103
node_not_to_step_past
103104
):
105+
"""
106+
This is a super hacky way of getting the first node after a statement.
107+
We do this because we visit a statement and keep on visiting and get something in return that is rarely the first node.
108+
So we loop and loop backwards until we hit the statement or there is nothing to step back to.
109+
"""
104110
ingoing = None
111+
i = 0
105112
current_node = node
106113
while current_node.ingoing:
114+
# This is used because there may be multiple ingoing and loop will cause an infinite loop if we did [0]
115+
i = random.randrange(len(current_node.ingoing))
107116
# e.g. We don't want to step past the Except of an Except basic block
108-
if current_node.ingoing[0] == node_not_to_step_past:
117+
if current_node.ingoing[i] == node_not_to_step_past:
109118
break
110119
ingoing = current_node.ingoing
111-
current_node = current_node.ingoing[0]
120+
current_node = current_node.ingoing[i]
112121
if ingoing:
113-
return ingoing[0]
122+
return ingoing[i]
114123
return current_node
115124

116125

0 commit comments

Comments
 (0)