From: Tomasz Bochenski Date: Thu, 27 Apr 2017 14:10:43 +0000 (+0200) Subject: [Base-utils][Format] i18n_format_format bug fixed X-Git-Tag: submit/tizen/20170818.060344~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=84eb47287f614a8fc029c07f6e998045e44dc8d2;p=platform%2Fcore%2Fapi%2Fbase-utils.git [Base-utils][Format] i18n_format_format bug fixed Change-Id: Iee73ff753789b6e7c76f2b57fe011fb78c6acbed Signed-off-by: Tomasz Bochenski --- 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); }