UninitializedStateVarsDetection: dont report unused variables

SlithIr Printer: printer modifiers IRs
SlithIR: fix missing condition conversion
pull/62/head
Josselin 6 years ago
parent 517a73ca33
commit 12d0013095
  1. 12
      slither/detectors/variables/uninitialized_state_variables.py
  2. 10
      slither/printers/summary/slithir.py
  3. 6
      slither/slithir/convert.py

@ -45,10 +45,20 @@ class UninitializedStateVarsDetection(AbstractDetector):
return ret return ret
@staticmethod
def read_variables(contract):
ret = []
for f in contract.all_functions_called + contract.modifiers:
ret += f.state_variables_read
return ret
def detect_uninitialized(self, contract): def detect_uninitialized(self, contract):
written_variables = self.written_variables(contract) written_variables = self.written_variables(contract)
read_variables = self.read_variables(contract)
return [(variable, contract.get_functions_reading_from_variable(variable)) return [(variable, contract.get_functions_reading_from_variable(variable))
for variable in contract.state_variables if variable not in written_variables and not variable.expression] for variable in contract.state_variables if variable not in written_variables and\
not variable.expression and\
variable in read_variables]
def detect(self): def detect(self):
""" Detect uninitialized state variables """ Detect uninitialized state variables

@ -29,4 +29,14 @@ class PrinterSlithIR(AbstractPrinter):
print('\t\tIRs:') print('\t\tIRs:')
for ir in node.irs: for ir in node.irs:
print('\t\t\t{}'.format(ir)) print('\t\t\t{}'.format(ir))
for modifier in contract.modifiers:
if modifier.contract == contract:
print('\tModifier {}'.format(modifier.full_name))
for node in modifier.nodes:
print(node)
if node.expression:
print('\t\tExpression: {}'.format(node.expression))
print('\t\tIRs:')
for ir in node.irs:
print('\t\t\t{}'.format(ir))
self.info(txt) self.info(txt)

@ -636,6 +636,12 @@ def convert_expression(expression, node):
if isinstance(expression, Identifier) and node.type == NodeType.RETURN: if isinstance(expression, Identifier) and node.type == NodeType.RETURN:
result = [Return(expression.value)] result = [Return(expression.value)]
return result return result
if isinstance(expression, Literal) and node.type in [NodeType.IF, NodeType.IFLOOP]:
result = [Condition(Constant(expression.value))]
return result
if isinstance(expression, Identifier) and node.type in [NodeType.IF, NodeType.IFLOOP]:
result = [Condition(expression.value)]
return result
visitor = ExpressionToSlithIR(expression) visitor = ExpressionToSlithIR(expression)
result = visitor.result() result = visitor.result()

Loading…
Cancel
Save