diff --git a/utils/slither_format/formatters/naming_convention.py b/utils/slither_format/formatters/naming_convention.py index d568f4e78..323732142 100644 --- a/utils/slither_format/formatters/naming_convention.py +++ b/utils/slither_format/formatters/naming_convention.py @@ -409,7 +409,7 @@ def _explore_irs(slither, irs, result, target, convert): def _explore_functions(slither, functions, result, target, convert): for function in functions: - _explore_variables_declaration(slither, function.local_variables, result, target, convert) + _explore_variables_declaration(slither, function.variables, result, target, convert) _explore_modifiers_calls(slither, function, result, target, convert) _explore_irs(slither, function.all_slithir_operations(), result, target, convert) diff --git a/utils/slither_format/slither_format.py b/utils/slither_format/slither_format.py index 458649579..1e024e774 100644 --- a/utils/slither_format/slither_format.py +++ b/utils/slither_format/slither_format.py @@ -59,14 +59,20 @@ def slither_format(slither, **kwargs): for file in result['patches']: original_txt = slither.source_code[file] patched_txt = original_txt - for patch in result['patches'][file]: - patched_txt = apply_patch(patched_txt, patch) + offset = 0 + patches = result['patches'][file] + patches.sort(key=lambda x:x['start']) + if not all(patches[i]['end'] <= patches[i+1]['end'] for i in range(len(patches)-1)): + logger.info(f'Impossible to generate patch; patches collisions: {patches}') + continue + for patch in patches: + patched_txt, offset = apply_patch(patched_txt, patch, offset) diff = create_diff(slither, original_txt, patched_txt, file) result['paches_diff'] = diff if skip_file_generation: continue if not diff: - logger.info(f'Empty patch generated {result}') + logger.info(f'Impossible to generate patch; empty {result}') continue path = os.path.join(export, f'fix_{counter}.patch') logger.info(f'\t- {path}') diff --git a/utils/slither_format/utils/patches.py b/utils/slither_format/utils/patches.py index cf4bacb72..a8fb48d11 100644 --- a/utils/slither_format/utils/patches.py +++ b/utils/slither_format/utils/patches.py @@ -14,11 +14,14 @@ def create_patch(result, file, start, end, old_str, new_str): result['patches'][file].append(p) -def apply_patch(original_txt, patch): - patched_txt = original_txt[:int(patch['start'])] +def apply_patch(original_txt, patch, offset): + patched_txt = original_txt[:int(patch['start'] + offset)] patched_txt += patch['new_string'] - patched_txt += original_txt[int(patch['end']):] - return patched_txt + patched_txt += original_txt[int(patch['end'] + offset):] + + # Keep the diff of text added or sub, in case of multiple patches + patch_length_diff = len(patch['new_string']) - (patch['end'] - patch['start']) + return patched_txt, patch_length_diff + offset def create_diff(slither, original_txt, patched_txt, filename):