src: fix external string length calculation
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: https://github.com/iojs/io.js/pull/1042 Reviewed-By: Trevor Norris <trev.norris@gmail.com>
This commit is contained in:
parent
e2fb733a95
commit
2eda2d6096
@ -263,7 +263,7 @@ bool StringBytes::GetExternalParts(Isolate* isolate,
|
|||||||
const String::ExternalStringResource* ext;
|
const String::ExternalStringResource* ext;
|
||||||
ext = str->GetExternalStringResource();
|
ext = str->GetExternalStringResource();
|
||||||
*data = reinterpret_cast<const char*>(ext->data());
|
*data = reinterpret_cast<const char*>(ext->data());
|
||||||
*len = ext->length();
|
*len = ext->length() * sizeof(*ext->data());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -317,7 +317,7 @@ size_t StringBytes::Write(Isolate* isolate,
|
|||||||
|
|
||||||
case UCS2:
|
case UCS2:
|
||||||
if (is_extern)
|
if (is_extern)
|
||||||
memcpy(buf, data, len * 2);
|
memcpy(buf, data, len);
|
||||||
else
|
else
|
||||||
len = str->Write(reinterpret_cast<uint16_t*>(buf), 0, buflen, flags);
|
len = str->Write(reinterpret_cast<uint16_t*>(buf), 0, buflen, flags);
|
||||||
if (IsBigEndian()) {
|
if (IsBigEndian()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user