Skip to content

Commit d0ff68d

Browse files
author
Jeff Brown
committed
Fix regression in CursorWindow.copyStingToBuffer.
Bug: 5332296 Change-Id: Iff9eed786f0a8293b6156f883a66a322ddad5e99
1 parent aa32c30 commit d0ff68d

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

core/jni/android_database_CursorWindow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ static void fillCharArrayBufferUTF(JNIEnv* env, jobject bufferObj,
267267
if (dataObj) {
268268
if (size) {
269269
jchar* data = static_cast<jchar*>(env->GetPrimitiveArrayCritical(dataObj, NULL));
270-
utf8_to_utf16(reinterpret_cast<const uint8_t*>(str), len,
270+
utf8_to_utf16_no_null_terminator(reinterpret_cast<const uint8_t*>(str), len,
271271
reinterpret_cast<char16_t*>(data));
272272
env->ReleasePrimitiveArrayCritical(dataObj, data, 0);
273273
}

include/utils/Unicode.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,13 @@ void utf8_to_utf32(const char* src, size_t src_len, char32_t* dst);
149149
*/
150150
ssize_t utf8_to_utf16_length(const uint8_t* src, size_t srcLen);
151151

152+
/**
153+
* Convert UTF-8 to UTF-16 including surrogate pairs.
154+
* Returns a pointer to the end of the string (where a null terminator might go
155+
* if you wanted to add one).
156+
*/
157+
char16_t* utf8_to_utf16_no_null_terminator(const uint8_t* src, size_t srcLen, char16_t* dst);
158+
152159
/**
153160
* Convert UTF-8 to UTF-16 including surrogate pairs. The destination buffer
154161
* must be large enough to hold the result as measured by utf8_to_utf16_length

libs/utils/Unicode.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -542,11 +542,7 @@ ssize_t utf8_to_utf16_length(const uint8_t* u8str, size_t u8len)
542542
return u16measuredLen;
543543
}
544544

545-
/**
546-
* Convert a UTF-8 string to UTF-16. The destination UTF-16 buffer must have
547-
* space for NULL at the end.
548-
*/
549-
void utf8_to_utf16(const uint8_t* u8str, size_t u8len, char16_t* u16str)
545+
char16_t* utf8_to_utf16_no_null_terminator(const uint8_t* u8str, size_t u8len, char16_t* u16str)
550546
{
551547
const uint8_t* const u8end = u8str + u8len;
552548
const uint8_t* u8cur = u8str;
@@ -569,7 +565,12 @@ void utf8_to_utf16(const uint8_t* u8str, size_t u8len, char16_t* u16str)
569565

570566
u8cur += u8len;
571567
}
572-
*u16cur = 0;
568+
return u16cur;
569+
}
570+
571+
void utf8_to_utf16(const uint8_t* u8str, size_t u8len, char16_t* u16str) {
572+
char16_t* end = utf8_to_utf16_no_null_terminator(u8str, u8len, u16str);
573+
*end = 0;
573574
}
574575

575576
}

0 commit comments

Comments
 (0)