Changes use of parameters_src and returns_src to source_mapping objects instead of raw source text.

pull/238/head
rajeevgopalakrishna 6 years ago
parent f0fa6c6d2c
commit 36afdca50e
  1. 2
      utils/slither_format/format_constant_function.py
  2. 2
      utils/slither_format/format_external_function.py
  3. 6
      utils/slither_format/format_naming_convention.py

@ -13,7 +13,7 @@ class FormatConstantFunction:
if not Found: if not Found:
for function in contract.functions: for function in contract.functions:
if contract.name == element['contract']['name'] and function.name == element['name']: if contract.name == element['contract']['name'] and function.name == element['name']:
FormatConstantFunction.create_patch(slither, patches, element['source_mapping']['filename_absolute'], ["view","pure","constant"], "", int(function.parameters_src.split(':')[0]), int(function.returns_src.split(':')[0])) FormatConstantFunction.create_patch(slither, patches, element['source_mapping']['filename_absolute'], ["view","pure","constant"], "", int(function.parameters_src.source_mapping['start']), int(function.returns_src.source_mapping['start']))
Found = True Found = True
@staticmethod @staticmethod

@ -14,7 +14,7 @@ class FormatExternalFunction:
# to external because external function parameters are allocated in calldata region which is # to external because external function parameters are allocated in calldata region which is
# non-modifiable. See https://solidity.readthedocs.io/en/develop/types.html#data-location # non-modifiable. See https://solidity.readthedocs.io/en/develop/types.html#data-location
if not FormatExternalFunction.function_parameters_written(function): if not FormatExternalFunction.function_parameters_written(function):
FormatExternalFunction.create_patch(slither, patches, element['source_mapping']['filename_absolute'], "public", "external", int(function.parameters_src.split(':')[0]), int(function.returns_src.split(':')[0])) FormatExternalFunction.create_patch(slither, patches, element['source_mapping']['filename_absolute'], "public", "external", int(function.parameters_src.source_mapping['start']), int(function.returns_src.source_mapping['start']))
Found = True Found = True
break break

@ -168,13 +168,13 @@ class FormatNamingConvention:
for m in function.modifiers: for m in function.modifiers:
if (m.name == name): if (m.name == name):
in_file_str = slither.source_code[in_file] in_file_str = slither.source_code[in_file]
old_str_of_interest = in_file_str[int(function.parameters_src.split(':')[0]):int(function.returns_src.split(':')[0])] old_str_of_interest = in_file_str[int(function.parameters_src.source_mapping['start']):int(function.returns_src.source_mapping['start'])]
(new_str_of_interest, num_repl) = re.subn(name, name[0].lower()+name[1:],old_str_of_interest,1) (new_str_of_interest, num_repl) = re.subn(name, name[0].lower()+name[1:],old_str_of_interest,1)
if num_repl != 0: if num_repl != 0:
patch = { patch = {
"detector" : "naming-convention (modifier uses)", "detector" : "naming-convention (modifier uses)",
"start" : int(function.parameters_src.split(':')[0]), "start" : int(function.parameters_src.source_mapping['start']),
"end" : int(function.returns_src.split(':')[0]), "end" : int(function.returns_src.source_mapping['start']),
"old_string" : old_str_of_interest, "old_string" : old_str_of_interest,
"new_string" : new_str_of_interest "new_string" : new_str_of_interest
} }

Loading…
Cancel
Save