diff --git a/libutils/Unicode.cpp b/libutils/Unicode.cpp index a66e3bbbb..1ee1a0b57 100644 --- a/libutils/Unicode.cpp +++ b/libutils/Unicode.cpp @@ -342,7 +342,8 @@ void utf16_to_utf8(const char16_t* src, size_t src_len, char* dst) while (cur_utf16 < end_utf16) { char32_t utf32; // surrogate pairs - if ((*cur_utf16 & 0xFC00) == 0xD800) { + if((*cur_utf16 & 0xFC00) == 0xD800 && (cur_utf16 + 1) < end_utf16 + && (*(cur_utf16 + 1) & 0xFC00) == 0xDC00) { utf32 = (*cur_utf16++ - 0xD800) << 10; utf32 |= *cur_utf16++ - 0xDC00; utf32 += 0x10000;