evas test - check return of ftell and malloc and handle properly

fix CID 1400871
This commit is contained in:
Carsten Haitzler 2020-09-19 23:43:58 +01:00
parent 485ecc24ed
commit 82de87dfc5
1 changed files with 10 additions and 0 deletions

View File

@ -643,8 +643,18 @@ _file_to_memory(const char *filename, char **result)
fseek(f, 0, SEEK_END);
size = ftell(f);
if (size <= 0)
{
fclose(f);
return -1;
}
fseek(f, 0, SEEK_SET);
*result = (char *)malloc(size + 1);
if (*result == NULL)
{
fclose(f);
return -1;
}
if ((size_t)size != fread(*result, sizeof(char), size, f))
{
free(*result);