/** Completely free a pack_t. */
static inline void free_addr_set(pack_t *pack, knot_mm_t *pool)
{
- if (unlikely(!pack)) {
+ if (!kr_assume(pack)) {
/* promised we don't store NULL packs */
- assert(false);
return;
}
pack_clear_mm(*pack, mm_free, pool);
int kr_zonecut_add(struct kr_zonecut *cut, const knot_dname_t *ns, const void *data, int len)
{
- if (!cut || !ns || !cut->nsset || (data && len <= 0)) {
- assert(!EINVAL);
+ if (!kr_assume(cut && ns && cut->nsset && (!data || len > 0)))
return kr_error(EINVAL);
- }
/* Disabled; add_reverse_pair() misuses this for domain name in rdata. */
if (false && data && len != sizeof(struct in_addr)
&& len != sizeof(struct in6_addr)) {
- assert(!EINVAL);
+ (void)!kr_assume(!EINVAL);
return kr_error(EINVAL);
}
if (pack->len == 0) {
free_addr_set(pack, cut->pool);
ret = trie_del(cut->nsset, (const char *)ns, knot_dname_size(ns), NULL);
- assert(ret == 0); /* only KNOT_ENOENT and that *can't* happen */
- return (ret == 0) ? kr_ok() : kr_error(ret);
+ if (!kr_assume(ret == 0)) /* only KNOT_ENOENT and that *can't* happen */
+ return kr_error(ret);
+ return kr_ok();
}
return ret;
int ret = trie_del(cut->nsset, (const char *)ns, knot_dname_size(ns),
(trie_val_t *)&pack);
if (ret) { /* deletion failed */
- assert(ret == KNOT_ENOENT);
+ (void)!kr_assume(ret == KNOT_ENOENT);
return kr_error(ENOENT);
}
free_addr_set(pack, cut->pool);
bool kr_zonecut_is_empty(struct kr_zonecut *cut)
{
- if (!cut || !cut->nsset) {
- assert(false);
+ if (!kr_assume(cut && cut->nsset))
return true;
- }
return !trie_apply(cut->nsset, has_address, NULL);
}
rdlen = 16;
break;
default:
- assert(!EINVAL);
+ (void)!kr_assume(!EINVAL);
return AI_UNKNOWN;
}
++usable_cnt;
ret = pack_obj_push(addrs, rd->data, rd->len);
- assert(!ret); /* didn't fit because of incorrectly reserved memory */
+ (void)!kr_assume(!ret); /* didn't fit because of incorrectly reserved memory */
/* LATER: for now we lose quite some information here,
* as keeping it would need substantial changes on other places,
* and it turned out to be premature optimization (most likely).
pack_t **pack = (pack_t **)trie_get_ins(cut->nsset,
(const char *)ns_name, ns_size);
if (!pack) return kr_error(ENOMEM);
- assert(!*pack); /* not critical, really */
+ (void)!kr_assume(!*pack); /* not critical, really */
*pack = mm_alloc(cut->pool, sizeof(pack_t));
if (!*pack) return kr_error(ENOMEM);
pack_init(**pack);
const knot_dname_t *owner, uint16_t type, knot_mm_t *pool,
const struct kr_query *qry)
{
- if (!rr) {
- assert(!EINVAL);
+ if (!kr_assume(rr))
return kr_error(EINVAL);
- }
/* peek, check rank and TTL */
struct kr_cache_p peek;
int ret = kr_cache_peek_exact(cache, owner, type, &peek);
- if (ret != 0) {
+ if (ret != 0)
return ret;
- }
- if (!kr_rank_test(peek.rank, KR_RANK_SECURE)) {
+ if (!kr_rank_test(peek.rank, KR_RANK_SECURE))
return kr_error(ENOENT);
- }
int32_t new_ttl = kr_cache_ttl(&peek, qry, owner, type);
- if (new_ttl < 0) {
+ if (new_ttl < 0)
return kr_error(ESTALE);
- }
/* materialize a new RRset */
knot_rrset_free(*rr, pool);
*rr = mm_alloc(pool, sizeof(knot_rrset_t));
- if (*rr == NULL) {
+ if (*rr == NULL)
return kr_error(ENOMEM);
- }
owner = knot_dname_copy(/*const-cast*/(knot_dname_t *)owner, pool);
if (!owner) {
mm_free(pool, *rr);
const knot_dname_t *name, const struct kr_query *qry,
bool * restrict secured)
{
- if (!ctx || !cut || !name) {
- //assert(false);
+ if (!ctx || !cut || !name)
return kr_error(EINVAL);
- }
/* I'm not sure whether the caller always passes a clean state;
* mixing doesn't seem to make sense in any case, so let's clear it.
* We don't bother freeing the packs, as they're on mempool. */