From 0e3a1f1e84a0698f4885f047928baeaad5672d2d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tomasz=20Boche=C5=84ski?= Date: Tue, 8 Aug 2017 15:32:03 +0200 Subject: [PATCH] [Base-utils][MeasureFormat] i18n_measure_format_format bug fixed MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change-Id: Ic24150861c40bd0c6d7bd82fa666a881c2284d53 Signed-off-by: Tomasz Bocheński --- src/utils_i18n_measure_format.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) 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); } -- 2.34.1