Eolian: fix coverity issues.

CID 1216274
CID 1216275
CID 1216276
CID 1216277
CID 1216278
CID 1216279
CID 1216280
This commit is contained in:
Daniel Zaoui 2014-05-27 08:18:33 +03:00
parent 1aa3510666
commit b10a1b11f1
6 changed files with 26 additions and 17 deletions

View File

@ -28,7 +28,7 @@ _class_func_names_fill(const Eolian_Class class, const char *over_classname, con
{
current_class = class;
if (!class)
strcpy(current_classname, over_classname);
strncpy(current_classname, over_classname, sizeof(current_classname) - 1);
else
_class_name_concatenate(class, current_classname);

View File

@ -588,6 +588,7 @@ eo_source_end_generate(const Eolian_Class class, Eina_Strbuf *buf)
if (!str_classtype)
{
ERR ("Unknown class type for class %s !", classname);
free(classname);
return EINA_FALSE;
}

View File

@ -62,9 +62,8 @@ _function_exists(const char* func_name, Eina_Strbuf *buffer)
return EINA_TRUE;
}
}
default:
ptr++; /* so strstr doesn't fall again on func_name */
}
ptr++; /* so strstr doesn't fall again on func_name */
}
return EINA_FALSE;
}
@ -87,9 +86,8 @@ _type_exists(const char* type_name, Eina_Strbuf *buffer)
return EINA_TRUE;
}
}
default:
ptr++; /* so strstr doesn't fall again on type_name */
}
ptr++; /* so strstr doesn't fall again on type_name */
}
return EINA_FALSE;
}

View File

@ -310,7 +310,7 @@ _eapi_func_generate(const Eolian_Class class, Eolian_Function funcid, Eolian_Fun
if (rettype && (!ret_is_void))
{
char tmp_ret_str[0xFF];
sprintf (tmp_ret_str, "%s%s", ret_const?"const ":"", rettype?rettype:"void");
sprintf (tmp_ret_str, "%s%s", ret_const?"const ":"", rettype);
const char *dflt_ret_val =
eolian_function_return_dflt_value_get(funcid, ftype);
Eina_Bool had_star = !!strchr(rettype, '*');

View File

@ -131,17 +131,28 @@ _generate_impl_c_file(char *filename, const Eolian_Class class)
{
fseek(fd, 0, SEEK_END);
file_size = ftell(fd);
fseek(fd, 0, SEEK_SET);
char *content = malloc(file_size + 1);
fread(content, file_size, 1, fd);
content[file_size] = '\0';
fclose(fd);
if (!content)
if (file_size <= 0)
{
ERR("Couldnt read file %s", filename);
ERR("Couldnt determine length for file %s", filename);
goto end;
}
fseek(fd, 0, SEEK_SET);
char *content = malloc(file_size + 1);
if (!content)
{
ERR("Couldnt allocate memory for file %s", filename);
goto end;
}
if (0 == fread(content, file_size, 1, fd))
{
ERR("Couldnt read the %ld bytes of file %s", file_size, filename);
free(content);
goto end;
}
content[file_size] = '\0';
fclose(fd);
fd = NULL;
buffer = eina_strbuf_manage_new(content);
}
@ -164,10 +175,9 @@ _generate_impl_c_file(char *filename, const Eolian_Class class)
const char *text = eina_strbuf_string_get(buffer);
if (text) fputs(text, fd);
fclose(fd);
ret = EINA_TRUE;
end:
if (fd) fclose(fd);
eina_strbuf_free(buffer);
return ret;
}

View File

@ -223,7 +223,7 @@ eolian_type_find_by_alias(const char *alias)
Eina_Stringshare *shr = eina_stringshare_add(alias);
Type_Desc *cl = eina_hash_find(_types, shr);
eina_stringshare_del(shr);
return cl->type;
return cl?cl->type:NULL;
}
Eolian_Class