Skip to content

Commit

Permalink
Fix the foddy infinite loop
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinHock committed Mar 31, 2018
1 parent 153501f commit 104cf80
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
7 changes: 2 additions & 5 deletions example/november_2017_evaluation/infinite_loop/foddy.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ def recommended():
if is_google_auth():
location = get_location(http_auth)


def get_location(http_auth):
for i in range(len(events_result['items'])):
example = events_result['items'][i]['start']
if 'dateTime' in example.keys():
index_of_valid_event = i
break
if 'location' in events_result['items'][index_of_valid_event].keys():
location = events_result['items'][index_of_valid_event]['location']
else:
location = 'unspecified'
return location
return 5
6 changes: 5 additions & 1 deletion pyt/stmt_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,11 @@ def assignment_call_node(self, left_hand_label, ast_node):
self.undecided = True # Used for handling functions in assignments

call = self.visit(ast_node.value)
call_label = call.left_hand_side
try:
call_label = call.left_hand_side
except AttributeError:
print('Assigning from a void function is invalid Python')
exit(0)

if isinstance(call, BBorBInode):
# Necessary to know e.g.
Expand Down
15 changes: 12 additions & 3 deletions pyt/stmt_visitor_helper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ast
import random
from collections import namedtuple

from .node_types import (
Expand Down Expand Up @@ -101,16 +102,24 @@ def get_first_node(
node,
node_not_to_step_past
):
"""
This is a super hacky way of getting the first node after a statement.
We do this because we visit a statement and keep on visiting and get something in return that is rarely the first node.
So we loop and loop backwards until we hit the statement or there is nothing to step back to.
"""
ingoing = None
i = 0
current_node = node
while current_node.ingoing:
# This is used because there may be multiple ingoing and loop will cause an infinite loop if we did [0]
i = random.randrange(len(current_node.ingoing))
# e.g. We don't want to step past the Except of an Except basic block
if current_node.ingoing[0] == node_not_to_step_past:
if current_node.ingoing[i] == node_not_to_step_past:
break
ingoing = current_node.ingoing
current_node = current_node.ingoing[0]
current_node = current_node.ingoing[i]
if ingoing:
return ingoing[0]
return ingoing[i]
return current_node


Expand Down

0 comments on commit 104cf80

Please sign in to comment.