summaryrefslogtreecommitdiff
path: root/src/string_bytes.cc
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2015-03-03 14:46:16 +0100
committerBen Noordhuis <info@bnoordhuis.nl>2015-03-05 20:44:19 +0100
commit2eda2d609658826c559fca1944b0e6aafb9d1344 (patch)
treef11dccb20c748ca1fabaee5b7c376585d61af042 /src/string_bytes.cc
parente2fb733a951a51821c03cf83400607522da52e44 (diff)
downloadandroid-node-v8-2eda2d609658826c559fca1944b0e6aafb9d1344.tar.gz
android-node-v8-2eda2d609658826c559fca1944b0e6aafb9d1344.tar.bz2
android-node-v8-2eda2d609658826c559fca1944b0e6aafb9d1344.zip
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>
Diffstat (limited to 'src/string_bytes.cc')
-rw-r--r--src/string_bytes.cc4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/string_bytes.cc b/src/string_bytes.cc
index 4a91f25048..1f5e592a32 100644
--- a/src/string_bytes.cc
+++ b/src/string_bytes.cc
@@ -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;
}
@@ -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()) {