Skip to content

Commit

Permalink
Fix unused state: #333 lead to miss some results
Browse files Browse the repository at this point in the history
  • Loading branch information
montyly committed Oct 1, 2019
1 parent 59691a8 commit 0c91571
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions slither/detectors/variables/unused_state_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def detect_unused(self, contract):
# Get all the variables read in all the functions and modifiers

all_functions = (contract.all_functions_called + contract.modifiers)
variables_used = [x.state_variables_read + x.state_variables_written for x in
all_functions]
variables_used = [x.state_variables_read for x in all_functions]
variables_used += [x.state_variables_written for x in all_functions if not x.is_constructor_variables]

array_candidates = [x.variables for x in all_functions]
array_candidates = [i for sl in array_candidates for i in sl] + contract.state_variables
Expand All @@ -41,9 +41,12 @@ def detect_unused(self, contract):
array_candidates = [i for sl in array_candidates for i in sl]
array_candidates = [v for v in array_candidates if isinstance(v, StateVariable)]



# Flat list
variables_used = [item for sublist in variables_used for item in sublist]
variables_used = list(set(variables_used + array_candidates))

# Return the variables unused that are not public
return [x for x in contract.variables if
x not in variables_used and x.visibility != 'public']
Expand Down

0 comments on commit 0c91571

Please sign in to comment.