[Base-utils][Format] i18n_format_format bug fixed 29/127529/4
authorTomasz Bochenski <t.bochenski@samsung.com>
Thu, 27 Apr 2017 14:10:43 +0000 (16:10 +0200)
committerhyunjee Kim <hj0426.kim@samsung.com>
Mon, 7 Aug 2017 05:18:03 +0000 (05:18 +0000)
Change-Id: Iee73ff753789b6e7c76f2b57fe011fb78c6acbed
Signed-off-by: Tomasz Bochenski <t.bochenski@samsung.com>
src/utils_i18n_format.cpp

index f55a375..f32eb7e 100644 (file)
@@ -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);
 }