diff --git a/rEFIt_UEFI/cpp_foundation/unicode_conversions.cpp b/rEFIt_UEFI/cpp_foundation/unicode_conversions.cpp index 100227a15..30ed3b5ed 100755 --- a/rEFIt_UEFI/cpp_foundation/unicode_conversions.cpp +++ b/rEFIt_UEFI/cpp_foundation/unicode_conversions.cpp @@ -329,8 +329,13 @@ size_t utf32_string_from_utf8_string(char32_t* dst, size_t dst_max_size, const c { if ( dst_max_size <= 0 ) return 0; size_t size = utf32_stringnn_from_utf8_string(dst, dst_max_size, s); - *(dst+size) = 0; - return size; + if ( size >= dst_max_size ) { + *(dst + dst_max_size - 1) = 0; + return dst_max_size-1; + }else{ + *(dst + size) = 0; + return size; + } } // //size_t utf32_string_from_utf8_string(char32_t* dst, size_t dst_max_size, const char* s) @@ -866,7 +871,7 @@ size_t utf32_stringnn_from_utf16_string(char32_t* dst, size_t dst_max_size, cons if ( !s ) return 0; char32_t* p = dst; - char32_t* p_max = dst + dst_max_size - 1; + char32_t* p_max = dst + dst_max_size; char32_t c; while ( *s && p < p_max ) { diff --git a/rEFIt_UEFI/cpp_foundation/unicode_conversions.h b/rEFIt_UEFI/cpp_foundation/unicode_conversions.h index f0c759d35..2d22e5083 100644 --- a/rEFIt_UEFI/cpp_foundation/unicode_conversions.h +++ b/rEFIt_UEFI/cpp_foundation/unicode_conversions.h @@ -103,9 +103,17 @@ size_t utf8_size_of_utf32_string_len(const char32_t* s, size_t len); size_t utf32_size_of_utf8_string(const char* s); size_t utf32_size_of_utf8_string_len(const char* s, size_t len); +/* + * Convert s to dst. Do not add null terminator. + * Return the number of utf32 char written + */ size_t utf32_stringnn_from_utf8_string(char32_t* dst, size_t dst_max_size, const char* s); size_t utf32_string_from_utf8_string(char32_t* dst, size_t dst_max_size, const char* s); size_t utf32_string_from_utf8_string_len(char32_t* dst, size_t dst_max_size, const char* s, size_t len); +/* +* Convert s to dst. Do not add null terminator. +* Return the number of utf8 char written +*/ size_t utf8_stringnn_from_utf32_string(char* dst, size_t dst_max_size, const char32_t *s); size_t utf8_string_from_utf32_string(char* dst, size_t dst_max_size, const char32_t *s); size_t utf8_string_from_utf32_string_len(char* dst, size_t dst_max_size, const char32_t *s, size_t len);