some minor optimizations for _e_font_fontconfig_name_parse() as well as realloc failure handling

SVN revision: 74417
This commit is contained in:
Mike Blumenkrantz 2012-07-26 07:08:22 +00:00
parent 7fd07d8712
commit d3f8ffeb61
1 changed files with 15 additions and 7 deletions

View File

@ -169,7 +169,7 @@ _e_font_fontconfig_name_parse(Eina_Hash **font_hash, E_Font_Properties *efp, con
if (s1)
{
char *s2, *name, *style;
int len;
int len, len2;
len = s1 - font;
name = calloc(sizeof(char), len + 1);
@ -179,15 +179,23 @@ _e_font_fontconfig_name_parse(Eina_Hash **font_hash, E_Font_Properties *efp, con
s2 = strchr(name, ',');
if (s2)
{
len = s2 - name;
name = realloc(name, sizeof(char) * len + 1);
memset(name, 0, sizeof(char) * len + 1);
strncpy(name, font, len);
len2 = s2 - name;
if (len2 > len)
{
s2 = realloc(name, sizeof(char) * len2 + 1);
if (!s2)
{
free(name);
EINA_LOG_CRIT("alloc!");
return NULL;
}
}
strncpy(name, font, len2);
}
if (strncmp(s1, E_TOK_STYLE, strlen(E_TOK_STYLE)) == 0)
if (strncmp(s1, E_TOK_STYLE, sizeof(E_TOK_STYLE) - 1) == 0)
{
style = s1 + strlen(E_TOK_STYLE);
style = s1 + sizeof(E_TOK_STYLE) - 1;
if (font_hash) efp = eina_hash_find(*font_hash, name);
if (!efp)