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

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

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

Loading…
Cancel
Save