From 84eb47287f614a8fc029c07f6e998045e44dc8d2 Mon Sep 17 00:00:00 2001 From: Tomasz Bochenski Date: Thu, 27 Apr 2017 16:10:43 +0200 Subject: [PATCH] [Base-utils][Format] i18n_format_format bug fixed Change-Id: Iee73ff753789b6e7c76f2b57fe011fb78c6acbed Signed-off-by: Tomasz Bochenski --- src/utils_i18n_format.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/utils_i18n_format.cpp b/src/utils_i18n_format.cpp index f55a375..f32eb7e 100644 --- a/src/utils_i18n_format.cpp +++ b/src/utils_i18n_format.cpp @@ -56,11 +56,24 @@ int i18n_format_format(i18n_format_h format, i18n_formattable_h formattable, cha int32_t ulen = u_strlen(uchar_result); retv_if(ulen <= 0, I18N_ERROR_INVALID_PARAMETER); - *append_to = (char *) malloc(ulen + 1); + + /* + * UTF-16 uses at least two bytes, growing up to four bytes as necessary, + * that is why we multiply UChar by 4. + */ + int32_t char_len = 4*ulen+4; + char _append_to[char_len]; + memset(_append_to, 0x0, char_len); + u_austrcpy(_append_to, uchar_result); + + int32_t len = strlen(_append_to); + + *append_to = (char *) malloc(len+1); retv_if(*append_to == NULL, I18N_ERROR_OUT_OF_MEMORY); + memset(*append_to, 0x0, len+1); - u_austrcpy(*append_to, uchar_result); + COPY_STR(*append_to, _append_to, len+1); return _i18n_error_mapping(status); } -- 2.7.4