Merge pull request #252 from crytic/dev-fix-utf8lines

[WIP] Fix source mapping where utf8 char length != byte length
pull/264/head
Feist Josselin 6 years ago committed by GitHub
commit 4fe2eb169e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      slither/core/source_mapping/source_mapping.py
  2. 22
      tests/source_mapping.sol

@ -20,6 +20,7 @@ class SourceMapping(Context):
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
@ -29,17 +30,18 @@ class SourceMapping(Context):
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)

@ -0,0 +1,22 @@
contract A{
// ëëëëëëëëëëëëë
address unused;
address unused2;
//
address unused3;
address unused4;
//
address used;
}
Loading…
Cancel
Save