Skip to content

Commit

Permalink
Merge pull request #252 from crytic/dev-fix-utf8lines
Browse files Browse the repository at this point in the history
[WIP] Fix source mapping where utf8 char length != byte length
  • Loading branch information
montyly authored May 21, 2019
2 parents 9136391 + c1fc109 commit 4fe2eb1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
10 changes: 6 additions & 4 deletions slither/core/source_mapping/source_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def _compute_line(source_code, start, length):
Not done in an efficient way
"""
source_code = source_code.encode('utf-8')
total_length = len(source_code)
source_code = source_code.splitlines(True)
counter = 0
Expand All @@ -29,17 +30,18 @@ def _compute_line(source_code, start, length):
ending_column = None
while counter < total_length:
# Determine the length of the line, and advance the line number
lineLength = len(source_code[i])
line_content = source_code[i]
line_length = len(line_content)
i = i + 1

# Determine our column numbers.
if starting_column is None and counter + lineLength > start:
if starting_column is None and counter + line_length > start:
starting_column = (start - counter) + 1
if starting_column is not None and ending_column is None and counter + lineLength > start + length:
if starting_column is not None and ending_column is None and counter + line_length > start + length:
ending_column = ((start + length) - counter) + 1

# Advance the current position counter, and determine line numbers.
counter += lineLength
counter += line_length
if counter > start:
lines.append(i)

Expand Down
22 changes: 22 additions & 0 deletions tests/source_mapping.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
contract A{

// ëëëëëëëëëëëëë这这这这这这这这这这

address unused;


address unused2;


// ই এই এই এইই এই এই এইই এই এই এই

address unused3;


address unused4;

// 这这这这这这这这这这这这这这这这这这这这这这这这这这这这这这这这这这这这这这这这这这这这
address used;


}

0 comments on commit 4fe2eb1

Please sign in to comment.