Skip to content
Snippets Groups Projects
Verified Commit d3f8035b authored by Tomas Krizek's avatar Tomas Krizek
Browse files

lib/cache/entry_list.c: replace asserts

parent 9587a63f
No related branches found
No related tags found
1 merge request!1146lib/utils: define kr_require(), kr_assume() macros
......@@ -15,7 +15,8 @@ static int entry_h_len(knot_db_val_t val);
void entry_list_memcpy(struct entry_apex *ea, entry_list_t list)
{
assert(ea);
if (!kr_assume(ea))
return;
memset(ea, 0, offsetof(struct entry_apex, data));
ea->has_ns = list[EL_NS ].len;
ea->has_cname = list[EL_CNAME ].len;
......@@ -38,11 +39,8 @@ void entry_list_memcpy(struct entry_apex *ea, entry_list_t list)
int entry_list_parse(const knot_db_val_t val, entry_list_t list)
{
const bool ok = val.data && val.len && list;
if (!ok) {
assert(!EINVAL);
if (!kr_assume(val.data && val.len && list))
return kr_error(EINVAL);
}
/* Parse the apex itself (nsec parameters). */
const struct entry_apex *ea = entry_apex_consistent(val);
if (!ea) {
......@@ -83,26 +81,25 @@ int entry_list_parse(const knot_db_val_t val, entry_list_t list)
case EL_NS: has_type = ea->has_ns; break;
case EL_CNAME: has_type = ea->has_cname; break;
case EL_DNAME: has_type = ea->has_dname; break;
default: assert(false); return kr_error(EINVAL); /* something very bad */
default:
(void)!kr_assume(!EINVAL);
return kr_error(EINVAL); /* something very bad */
}
if (!has_type) {
list[i].len = 0;
continue;
}
if (it >= it_bound) {
assert(!EILSEQ);
if (!kr_assume(it < it_bound))
return kr_error(EILSEQ);
}
const int len = entry_h_len(
(knot_db_val_t){ .data = (void *)it, .len = it_bound - it });
if (len < 0) {
assert(false);
if (!kr_assume(len >= 0))
return kr_error(len);
}
list[i].len = len;
it += to_even(len);
}
assert(it == it_bound);
if (!kr_assume(it == it_bound)) /* better not use it; might be "damaged" */
return kr_error(EILSEQ);
return kr_ok();
}
......@@ -121,10 +118,8 @@ static int entry_h_len(const knot_db_val_t val)
int sets = 2;
while (sets-- > 0) {
d += KR_CACHE_RR_COUNT_SIZE + rdataset_dematerialized_size(d, NULL);
if (d > data_bound) {
assert(!EILSEQ);
if (!kr_assume(d <= data_bound))
return kr_error(EILSEQ);
}
}
} else { /* A "packet" (opaque ATM). */
uint16_t len;
......@@ -132,10 +127,8 @@ static int entry_h_len(const knot_db_val_t val)
memcpy(&len, d, sizeof(len));
d += 2 + to_even(len);
}
if (d > data_bound) {
assert(!EILSEQ);
if (!kr_assume(d <= data_bound))
return kr_error(EILSEQ);
}
return d - (uint8_t *)val.data;
}
......@@ -225,11 +218,8 @@ int entry_h_splice(
const struct kr_query *qry, struct kr_cache *cache, uint32_t timestamp)
{
//TODO: another review, perhaps incuding the API
const bool ok = val_new_entry && val_new_entry->len > 0;
if (!ok) {
assert(!EINVAL);
if (!kr_assume(val_new_entry && val_new_entry->len > 0))
return kr_error(EINVAL);
}
int i_type;
switch (type) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment