Skip to content

Commit

Permalink
Merge pull request #194 from crytic/dev-fix-line-numbers
Browse files Browse the repository at this point in the history
Bug fix for line number calculations
  • Loading branch information
montyly authored Apr 1, 2019
2 parents 6e83e11 + 8f13315 commit e328b65
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions slither/core/source_mapping/source_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ def _compute_line(source_code, start, length):
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)
Expand Down
6 changes: 3 additions & 3 deletions slither/solc_parsing/slitherSolc.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def _parse_contracts_from_loaded_json(self, data_loaded, filename):
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

Expand Down Expand Up @@ -152,13 +152,13 @@ def _parse_source_unit(self, data, filename):

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

Expand Down

0 comments on commit e328b65

Please sign in to comment.