Improve support for break with presence of nested loops (fix 141)

pull/169/head
Josselin 6 years ago
parent 1073a04e90
commit 29862ea541
  1. 11
      slither/solc_parsing/declarations/function.py

@ -647,20 +647,23 @@ class FunctionSolc(Function):
self._remove_incorrect_edges()
self._remove_alone_endif()
def _find_end_loop(self, node, visited):
def _find_end_loop(self, node, visited, counter):
# counter allows to explore nested loop
if node in visited:
return None
if node.type == NodeType.ENDLOOP:
if counter == 0:
return node
counter -= 1
# nested loop
if node.type == NodeType.STARTLOOP:
return None
counter += 1
visited = visited + [node]
for son in node.sons:
ret = self._find_end_loop(son, visited)
ret = self._find_end_loop(son, visited, counter)
if ret:
return ret
@ -682,7 +685,7 @@ class FunctionSolc(Function):
return None
def _fix_break_node(self, node):
end_node = self._find_end_loop(node, [])
end_node = self._find_end_loop(node, [], 0)
if not end_node:
logger.error('Break in no-loop context {}'.format(node))

Loading…
Cancel
Save