Skip to content

Commit

Permalink
src: fix external string length calculation
Browse files Browse the repository at this point in the history
Make StringBytes::GetExternalParts() return the byte length for two-byte
strings, not the character length.  Its callers operate on bytes, not
characters.

This also fixes StringBytes::Size() reporting only half of the actual
number of bytes for external two-byte strings.

PR-URL: #1042
Reviewed-By: Trevor Norris <[email protected]>
  • Loading branch information
bnoordhuis committed Mar 5, 2015
1 parent e2fb733 commit 2eda2d6
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/string_bytes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ bool StringBytes::GetExternalParts(Isolate* isolate,
const String::ExternalStringResource* ext;
ext = str->GetExternalStringResource();
*data = reinterpret_cast<const char*>(ext->data());
*len = ext->length();
*len = ext->length() * sizeof(*ext->data());
return true;
}

Expand Down Expand Up @@ -317,7 +317,7 @@ size_t StringBytes::Write(Isolate* isolate,

case UCS2:
if (is_extern)
memcpy(buf, data, len * 2);
memcpy(buf, data, len);
else
len = str->Write(reinterpret_cast<uint16_t*>(buf), 0, buflen, flags);
if (IsBigEndian()) {
Expand Down

0 comments on commit 2eda2d6

Please sign in to comment.