diff --git a/slither/core/source_mapping/source_mapping.py b/slither/core/source_mapping/source_mapping.py index f63d0278e..22dabca31 100644 --- a/slither/core/source_mapping/source_mapping.py +++ b/slither/core/source_mapping/source_mapping.py @@ -125,16 +125,7 @@ class SourceMapping(Context): @property def source_mapping_str(self): -# def relative_path(path): -# # Remove absolute path for printing -# # Truffle returns absolutePath -# splited_path = path.split(os.sep) -# if 'contracts' in splited_path: -# idx = splited_path.index('contracts') -# return os.sep.join(splited_path[idx-1:]) -# return path - - lines = self.source_mapping['lines'] + lines = self.source_mapping.get('lines', None) if not lines: lines = '' elif len(lines) == 1: diff --git a/slither/solc_parsing/slitherSolc.py b/slither/solc_parsing/slitherSolc.py index 1b3651f6d..eebb99935 100644 --- a/slither/solc_parsing/slitherSolc.py +++ b/slither/solc_parsing/slitherSolc.py @@ -148,6 +148,14 @@ class SlitherSolc(Slither): sourceUnit = re.findall('[0-9]*:[0-9]*:([0-9]*)', data['src']) if len(sourceUnit) == 1: sourceUnit = int(sourceUnit[0]) + if sourceUnit == -1: + # if source unit is not found + # We can still deduce it, by assigning to the last source_code added + # This works only for crytic compile. + # which used --combined-json ast, rather than --ast-json + # As a result -1 is not used as index + if not self.crytic_compile is None: + sourceUnit = len(self.source_code) self._source_units[sourceUnit] = name if os.path.isfile(name) and not name in self.source_code: