Add function.contains_assembly property

Use function.contains_assembly in unini local var detector
Clean code
pull/84/head
Josselin 6 years ago
parent 9770fe6276
commit de018d5f4d
  1. 4
      slither/core/declarations/function.py
  2. 6
      slither/detectors/variables/uninitialized_local_variables.py
  3. 28
      slither/solc_parsing/declarations/function.py

@ -54,7 +54,11 @@ class Function(ChildContract, SourceMapping):
self._expression_modifiers = []
self._modifiers = []
self._payable = False
self._contains_assembly = False
@property
def contains_assembly(self):
return self._contains_assembly
@property
def return_type(self):

@ -60,10 +60,6 @@ class UninitializedLocalVars(AbstractDetector):
self._detect_uninitialized(function, son, visited)
@staticmethod
def has_assembly_code(function):
return any(x.type == NodeType.ASSEMBLY for x in function.nodes)
def detect(self):
""" Detect uninitialized state variables
@ -79,7 +75,7 @@ class UninitializedLocalVars(AbstractDetector):
for contract in self.slither.contracts:
for function in contract.functions:
if function.is_implemented:
if self.has_assembly_code(function):
if function.contains_assembly:
continue
# dont consider storage variable, as they are detected by another detector
uninitialized_local_variables = [v for v in function.local_variables if not v.is_storage and v.uninitialized]

@ -135,33 +135,6 @@ class FunctionSolc(Function):
link_nodes(condition_node, endIf_node)
return endIf_node
# def _parse_if(self, ifStatement, node):
# # IfStatement = 'if' '(' Expression ')' Statement ( 'else' Statement )?
#
# children = ifStatement[self.get_children('children')]
# condition_node = self._new_node(NodeType.IF)
# #condition = parse_expression(children[0], self)
# condition = children[0]
# condition_node.add_unparsed_expression(condition)
#
# link_nodes(node, condition_node)
#
# trueStatement = self._parse_statement(children[1], condition_node)
#
#
# endIf_node = self._new_node(NodeType.ENDIF)
# link_nodes(trueStatement, endIf_node)
#
# if len(children) == 3:
# falseStatement = self._parse_statement(children[2], condition_node)
#
# link_nodes(falseStatement, endIf_node)
#
# else:
# link_nodes(condition_node, endIf_node)
#
# return endIf_node
def _parse_while(self, whileStatement, node):
# WhileStatement = 'while' '(' Expression ')' Statement
@ -536,6 +509,7 @@ class FunctionSolc(Function):
node = self._parse_block(statement, node)
elif name == 'InlineAssembly':
break_node = self._new_node(NodeType.ASSEMBLY, statement['src'])
self._contains_assembly = True
link_nodes(node, break_node)
node = break_node
elif name == 'DoWhileStatement':

Loading…
Cancel
Save