From: Tomasz Bocheński Date: Tue, 8 Aug 2017 13:32:03 +0000 (+0200) Subject: [Base-utils][MeasureFormat] i18n_measure_format_format bug fixed X-Git-Tag: submit/tizen/20180118.063705~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0e3a1f1e84a0698f4885f047928baeaad5672d2d;p=platform%2Fcore%2Fapi%2Fbase-utils.git [Base-utils][MeasureFormat] i18n_measure_format_format bug fixed Change-Id: Ic24150861c40bd0c6d7bd82fa666a881c2284d53 Signed-off-by: Tomasz Bocheński --- diff --git a/src/utils_i18n_measure_format.cpp b/src/utils_i18n_measure_format.cpp index 9b1cec9..03520e5 100644 --- a/src/utils_i18n_measure_format.cpp +++ b/src/utils_i18n_measure_format.cpp @@ -86,11 +86,24 @@ int i18n_measure_format_format(i18n_measure_format_h measure_format, retv_if(ulen <= 0, I18N_ERROR_INVALID_PARAMETER); + /* + * UTF-16 uses at least two bytes, growing up to four bytes as necessary, + * this 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); + i18n_ustring_copy_au(_append_to, uchar_result); + + int32_t len = strlen(_append_to); free(*append_to); - *append_to = (char *) malloc(ulen + 1); + *append_to = (char *) malloc(len+1); + retv_if(*append_to == NULL, I18N_ERROR_OUT_OF_MEMORY); - i18n_ustring_copy_au(*append_to, uchar_result); + memset(*append_to, 0x0, len+1); + + COPY_STR(*append_to, _append_to, len+1); return _i18n_error_mapping(status); }