Skip to content

Commit

Permalink
Python 3 byte string conversion issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrossard authored and flit committed May 17, 2020
1 parent fef063c commit f816900
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pyocd/debug/semihost.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,9 +473,9 @@ def _get_args(self, args, count):
def _get_string(self, ptr, length=None):
if length is not None:
data = self.context.read_memory_block8(ptr, length)
return str(bytearray(data))
return six.ensure_str(bytes(bytearray(data)), encoding="ascii", errors="ignore")

target_str = ''
target_str = six.ensure_str(bytes(bytearray('')), encoding="ascii", errors="ignore")
# TODO - use memory map to make sure we don't try to read off the end of memory
# Limit string size in case it isn't terminated.
while len(target_str) < MAX_STRING_LENGTH:
Expand All @@ -486,14 +486,14 @@ def _get_string(self, ptr, length=None):

# Found a null terminator, append data up to but not including the null
# and then exit the loop.
target_str += str(bytearray(data[:terminator]))
target_str += six.ensure_str(bytes(bytearray(data[:terminator])), encoding="ascii", errors="ignore")
break
except exceptions.TransferError:
# Failed to read some or all of the string.
break
except ValueError:
# No null terminator was found. Append all of data.
target_str += str(bytearray(data))
target_str += six.ensure_str(bytes(bytearray(data)), encoding="ascii", errors="ignore")
ptr += 32
return target_str

Expand Down

0 comments on commit f816900

Please sign in to comment.