From ad4fc1b5104ce75665c5de118cf2ac0d9d35e6a3 Mon Sep 17 00:00:00 2001 From: David Pokora Date: Thu, 28 Mar 2019 21:13:07 -0400 Subject: [PATCH 1/2] Fixed a bug where return carraiges would offset line number calculations (close #180) --- slither/solc_parsing/slitherSolc.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/slither/solc_parsing/slitherSolc.py b/slither/solc_parsing/slitherSolc.py index c2bffdd4c..5fa3c160e 100644 --- a/slither/solc_parsing/slitherSolc.py +++ b/slither/solc_parsing/slitherSolc.py @@ -89,7 +89,7 @@ class SlitherSolc(Slither): if 'sourcePaths' in data_loaded: for sourcePath in data_loaded['sourcePaths']: if os.path.isfile(sourcePath): - with open(sourcePath, encoding='utf8') as f: + with open(sourcePath, encoding='utf8', newline='') as f: source_code = f.read() self.source_code[sourcePath] = source_code @@ -152,13 +152,13 @@ class SlitherSolc(Slither): self._source_units[sourceUnit] = name if os.path.isfile(name) and not name in self.source_code: - with open(name, encoding='utf8') as f: + with open(name, encoding='utf8', newline='') as f: source_code = f.read() self.source_code[name] = source_code else: lib_name = os.path.join('node_modules', name) if os.path.isfile(lib_name) and not name in self.source_code: - with open(lib_name, encoding='utf8') as f: + with open(lib_name, encoding='utf8', newline='') as f: source_code = f.read() self.source_code[name] = source_code From 8f13315389f10fc2db2532900b0c5d0d98c9488c Mon Sep 17 00:00:00 2001 From: David Pokora Date: Fri, 29 Mar 2019 20:27:27 -0400 Subject: [PATCH 2/2] Updated line number calculation to use splitlines() instead of split('\n'). --- slither/core/source_mapping/source_mapping.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/slither/core/source_mapping/source_mapping.py b/slither/core/source_mapping/source_mapping.py index 2a0ffa6a6..c4df7ff24 100644 --- a/slither/core/source_mapping/source_mapping.py +++ b/slither/core/source_mapping/source_mapping.py @@ -19,12 +19,12 @@ class SourceMapping(Context): Not done in an efficient way """ total_length = len(source_code) - source_code = source_code.split('\n') + source_code = source_code.splitlines(True) counter = 0 i = 0 lines = [] while counter < total_length: - counter += len(source_code[i]) +1 + counter += len(source_code[i]) i = i+1 if counter > start: lines.append(i)