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);
}