eet: print errors any time an error occurs while decoding

Summary:
catching these errors was super annoying since the codebase is mostly
comprised of goto statements, so this should make future debugging easier
Depends on D6292

Reviewers: devilhorns, ManMower

Reviewed By: ManMower

Subscribers: cedric, #committers

Tags: #efl

Differential Revision: https://phab.enlightenment.org/D6293
This commit is contained in:
Mike Blumenkrantz 2018-06-15 16:34:32 -04:00
parent c74d964afa
commit 4631d4ce7e
1 changed files with 44 additions and 45 deletions

View File

@ -626,7 +626,7 @@ static int _eet_data_words_bigendian = -1;
Size, \
SubSize > 0 ? Data_Ret : NULL, \
SubSize); \
if (!Data_Ret) { goto Label; } \
EINA_SAFETY_ON_NULL_GOTO(Data_Ret, Label); \
} while (0)
#define EET_I_STRING 1 << 4
@ -1727,8 +1727,7 @@ case EET_T_ ## Type: type += EET_I_ ## Type; break;
size = eet_data_put_int(ed, &s, &size_ret);
/* FIXME: If something goes wrong the resulting file will be corrupted. */
if (!size)
goto on_error;
EINA_SAFETY_ON_TRUE_GOTO(!size, on_error);
eet_data_stream_write(ds, buf, 4);
@ -3610,12 +3609,12 @@ _eet_data_descriptor_decode(Eet_Free_Context *context,
memset(&chnk, 0, sizeof(Eet_Data_Chunk));
eet_data_chunk_get(ed, &chnk, data_in, size_in);
if (!chnk.name)
goto error;
EINA_SAFETY_ON_NULL_GOTO(chnk.name, error);
if (edd)
if (strcmp(chnk.name, edd->name))
goto error;
{
EINA_SAFETY_ON_TRUE_GOTO(strcmp(chnk.name, edd->name), error);
}
p = chnk.data;
if (ed)
@ -3659,6 +3658,7 @@ _eet_data_descriptor_decode(Eet_Free_Context *context,
case EET_G_UNION:
case EET_G_VARIANT:
default:
ERR("Decoding error!");
goto error;
}
}
@ -3674,8 +3674,7 @@ _eet_data_descriptor_decode(Eet_Free_Context *context,
/* get next data chunk */
memset(&echnk, 0, sizeof(Eet_Data_Chunk));
eet_data_chunk_get(ed, &echnk, p, size);
if (!echnk.name)
goto error; /* FIXME: don't REPLY on edd - work without */
EINA_SAFETY_ON_NULL_GOTO(echnk.name, error); /* FIXME: don't REPLY on edd - work without */
if (edd)
{
@ -3723,8 +3722,7 @@ _eet_data_descriptor_decode(Eet_Free_Context *context,
echnk.data,
((char *)echnk.data) + echnk.size,
dd);
if (ret <= 0)
goto error;
EINA_SAFETY_ON_TRUE_GOTO(ret <= 0, error);
child = eet_data_node_simple_type(type, echnk.name, dd);
@ -3744,8 +3742,7 @@ _eet_data_descriptor_decode(Eet_Free_Context *context,
&p,
&size);
if (ret <= 0)
goto error;
EINA_SAFETY_ON_TRUE_GOTO(ret <= 0, error);
}
/* advance to next chunk */
@ -3888,11 +3885,9 @@ eet_data_get_hash(Eet_Free_Context *context,
echnk->data,
((char *)echnk->data) + echnk->size,
&key);
if (ret <= 0)
goto on_error;
EINA_SAFETY_ON_TRUE_GOTO(ret <= 0, on_error);
if (!key)
goto on_error;
EINA_SAFETY_ON_NULL_GOTO(key, on_error);
/* Advance to next chunk */
NEXT_CHUNK((*p), (*size), (*echnk), ed);
@ -3900,13 +3895,15 @@ eet_data_get_hash(Eet_Free_Context *context,
/* Read value */
eet_data_chunk_get(ed, echnk, *p, *size);
if (!echnk->name)
goto on_error;
EINA_SAFETY_ON_NULL_GOTO(echnk->name, on_error);
if (ede)
if ((ede->group_type != echnk->group_type)
|| (ede->type != echnk->type))
goto on_error;
{
ERR("ERROR!");
goto on_error;
}
if (IS_POINTER_TYPE(echnk->type))
POINTER_TYPE_DECODE(context,
@ -4027,17 +4024,26 @@ eet_data_get_array(Eet_Free_Context *context,
eet_data_chunk_get(ed, echnk, *p, *size);
if (!echnk->name || strcmp(echnk->name, name) != 0)
goto on_error; /* get the data */
{
ERR("ERROR!");
goto on_error;
}
if ((echnk->group_type != group_type)
|| ((echnk->type != type) && (echnk->type != EET_T_NULL)))
goto on_error;
{
ERR("ERROR!");
goto on_error;
}
if (ede)
if ((ede->group_type != echnk->group_type)
|| ((echnk->type != ede->type) && (echnk->type != EET_T_NULL)))
goto on_error;
{
ERR("ERROR!");
goto on_error;
}
/* get the data */
/* get the destination pointer */
if (ede)
{
@ -4093,8 +4099,7 @@ eet_data_get_array(Eet_Free_Context *context,
else
array = eet_node_var_array_new(name, childs);
if (!array)
goto on_error;
EINA_SAFETY_ON_NULL_GOTO(array, on_error);
eet_node_struct_append(parent, name, array);
}
@ -4193,8 +4198,7 @@ eet_data_get_union(Eet_Free_Context *context,
echnk->data,
((char *)echnk->data) + echnk->size,
&union_type);
if (ret <= 0)
goto on_error;
EINA_SAFETY_ON_TRUE_GOTO(ret <= 0, on_error);
/* Advance to next chunk */
NEXT_CHUNK((*p), (*size), (*echnk), ed);
@ -4202,13 +4206,12 @@ eet_data_get_union(Eet_Free_Context *context,
/* Read value */
eet_data_chunk_get(ed, echnk, *p, *size);
if (!echnk->name)
goto on_error;
EINA_SAFETY_ON_NULL_GOTO(echnk->name, on_error);
if (ede)
{
EET_ASSERT(!(ede->group_type != group_type || ede->type != type),
goto on_error);
ERR("ERROR!"); goto on_error);
/* Search the structure of the union to decode */
for (i = 0; i < ede->subtype->elements.num; ++i)
@ -4233,7 +4236,7 @@ eet_data_get_union(Eet_Free_Context *context,
}
else
{
EET_ASSERT(sede->subtype, goto on_error);
EET_ASSERT(sede->subtype, ERR("ERROR!"); goto on_error);
data_ret = _eet_data_descriptor_decode(context,
ed,
sede->subtype,
@ -4241,8 +4244,7 @@ eet_data_get_union(Eet_Free_Context *context,
echnk->size,
data,
sede->subtype->size);
if (!data_ret)
goto on_error;
EINA_SAFETY_ON_NULL_GOTO(data_ret, on_error);
}
/* Set union type. */
@ -4273,6 +4275,7 @@ eet_data_get_union(Eet_Free_Context *context,
ed, NULL,
echnk->data, echnk->size,
NULL, 0);
ERR("ERROR!");
goto on_error;
}
@ -4422,8 +4425,7 @@ eet_data_get_variant(Eet_Free_Context *context,
echnk->data,
((char *)echnk->data) + echnk->size,
&union_type);
if (ret <= 0)
goto on_error;
EINA_SAFETY_ON_TRUE_GOTO(ret <= 0, on_error);
/* Advance to next chunk */
NEXT_CHUNK((*p), (*size), (*echnk), ed);
@ -4431,14 +4433,13 @@ eet_data_get_variant(Eet_Free_Context *context,
/* Read value */
eet_data_chunk_get(ed, echnk, *p, *size);
if (!echnk->name)
goto on_error;
EINA_SAFETY_ON_NULL_GOTO(echnk->name, on_error);
if (ede)
{
char *ut;
EET_ASSERT(ede->subtype, goto on_error);
EET_ASSERT(ede->subtype, ERR("ERROR!"); goto on_error);
if ((!ed) || (!ede->subtype->func.str_direct_alloc))
{
@ -4476,15 +4477,13 @@ eet_data_get_variant(Eet_Free_Context *context,
memset(&chnk, 0, sizeof(Eet_Data_Chunk));
eet_data_chunk_get(ed, &chnk, p2, size2);
if (!chnk.name)
goto on_error;
EINA_SAFETY_ON_NULL_GOTO(chnk.name, on_error);
ret = eet_group_codec[sede->group_type - 100].get
(context, ed, sede->subtype, sede, &chnk, sede->type,
sede->group_type, data, &p2, &size2);
if (ret <= 0)
goto on_error;
EINA_SAFETY_ON_TRUE_GOTO(ret <= 0, on_error);
/* advance to next chunk */
NEXT_CHUNK(p2, size2, chnk, ed);
@ -4523,8 +4522,7 @@ eet_data_get_variant(Eet_Free_Context *context,
Eet_Variant_Unknow *evu;
evu = calloc(1, sizeof (Eet_Variant_Unknow) + echnk->size - 1);
if (!evu)
goto on_error;
EINA_SAFETY_ON_NULL_GOTO(evu, on_error);
evu->size = echnk->size;
memcpy(evu->data, echnk->data, evu->size);
@ -4545,6 +4543,7 @@ eet_data_get_variant(Eet_Free_Context *context,
ed, NULL,
echnk->data, echnk->size,
NULL, 0);
ERR("ERROR!");
goto on_error;
}