OSDN Git Service

Unicode: specify destination length in utf8_to_utf16 methods
authorSergio Giro <sgiro@google.com>
Thu, 21 Jul 2016 13:46:35 +0000 (14:46 +0100)
committerMartijn Coenen <maco@google.com>
Thu, 25 Aug 2016 10:01:39 +0000 (12:01 +0200)
Change-Id: I5223caa7d42f4582a982609a898a02043265c6d3

libs/binder/Parcel.cpp

index e53a551..244da27 100644 (file)
@@ -784,7 +784,7 @@ status_t Parcel::writeUtf8AsUtf16(const std::string& str) {
     const uint8_t* strData = (uint8_t*)str.data();
     const size_t strLen= str.length();
     const ssize_t utf16Len = utf8_to_utf16_length(strData, strLen);
-    if (utf16Len < 0 || utf16Len> std::numeric_limits<int32_t>::max()) {
+    if (utf16Len < 0 || utf16Len > std::numeric_limits<int32_t>::max()) {
         return BAD_VALUE;
     }
 
@@ -799,7 +799,7 @@ status_t Parcel::writeUtf8AsUtf16(const std::string& str) {
         return NO_MEMORY;
     }
 
-    utf8_to_utf16(strData, strLen, (char16_t*)dst);
+    utf8_to_utf16(strData, strLen, (char16_t*)dst, (size_t) utf16Len + 1);
 
     return NO_ERROR;
 }