EINA_SAFETY_ON_NULL_RETURN_VAL(utf, NULL);
len = eina_unicode_utf8_get_len(utf);
- if (_len)
- *_len = len;
- buf = (Eina_Unicode *) calloc(sizeof(Eina_Unicode), (len + 1));
+ if (_len) *_len = len;
+ buf = malloc(sizeof(Eina_Unicode) * (len + 1));
if (!buf) return buf;
for (i = 0, ind = 0, uind = buf ; i < len ; i++, uind++)
EAPI char *
eina_unicode_unicode_to_utf8(const Eina_Unicode *uni, int *_len)
{
- char *buf;
+ char *buf, *buf2;
const Eina_Unicode *uind;
char *ind;
int ulen, len;
EINA_SAFETY_ON_NULL_RETURN_VAL(uni, NULL);
ulen = eina_unicode_strlen(uni);
- buf = (char *) calloc(ulen + 1, EINA_UNICODE_UTF8_BYTES_PER_CHAR);
+ buf = malloc((ulen + 1) * EINA_UNICODE_UTF8_BYTES_PER_CHAR);
+ if (!buf) return NULL;
len = 0;
for (uind = uni, ind = buf ; *uind ; uind++)
/* Do something */
}
}
- buf = realloc(buf, len + 1);
- buf[len] = '\0';
- if (_len)
- *_len = len;
+ buf2 = realloc(buf, len + 1);
+ if (!buf2)
+ {
+ free(buf);
+ return NULL;
+ }
+ buf2[len] = 0;
+ if (_len) *_len = len;
return buf;
}