diff options
author | Tomas Krizek <tomas.krizek@nic.cz> | 2021-05-25 14:17:23 +0200 |
---|---|---|
committer | Tomas Krizek <tomas.krizek@nic.cz> | 2021-05-25 14:40:30 +0200 |
commit | 2bc7b1e51318dc882c1f84073e9880cb77570bf7 (patch) | |
tree | ce932523c65e0997d5291e90083b976d80f59896 /daemon/bindings | |
parent | lib/dnssec/ta.c: replace asserts (diff) | |
download | knot-resolver-2bc7b1e51318dc882c1f84073e9880cb77570bf7.tar.xz knot-resolver-2bc7b1e51318dc882c1f84073e9880cb77570bf7.zip |
treewide: rename assumptions to kr_assert() / kr_fails_assert()
To (hopefully) improve readability, rename the typical macro usage of:
if (!kr_assume(x)) y; // to
if (kr_fails_assert(x)) y;
As a convenience, replace the assert without a return value to a more
simple version:
(void)!kr_assume(x); // becomes
kr_assert(x);
Diffstat (limited to 'daemon/bindings')
-rw-r--r-- | daemon/bindings/cache.c | 6 | ||||
-rw-r--r-- | daemon/bindings/net.c | 18 |
2 files changed, 12 insertions, 12 deletions
diff --git a/daemon/bindings/cache.c b/daemon/bindings/cache.c index cf6512f3..3ab1e532 100644 --- a/daemon/bindings/cache.c +++ b/daemon/bindings/cache.c @@ -10,7 +10,7 @@ static struct kr_cache * cache_assert_open(lua_State *L) { struct kr_cache *cache = &the_worker->engine->resolver.cache; - if (!kr_assume(cache) || !kr_cache_is_open(cache)) + if (kr_fails_assert(cache) || !kr_cache_is_open(cache)) lua_error_p(L, "no cache is open yet, use cache.open() or cache.size, etc."); return cache; } @@ -286,7 +286,7 @@ static void cache_dump(lua_State *L, knot_db_val_t keyval[]) } ret = !knot_dname_to_str(name, dname, sizeof(name)); - if (!kr_assume(!ret)) return; + if (kr_fails_assert(!ret)) return; /* If name typemap doesn't exist yet, create it */ lua_getfield(L, -1, name); @@ -367,7 +367,7 @@ static void cache_zone_import_cb(int state, void *param) { (void)state; struct worker_ctx *worker = param; - if (!kr_assume(worker && worker->z_import)) return; + if (kr_fails_assert(worker && worker->z_import)) return; zi_free(worker->z_import); worker->z_import = NULL; } diff --git a/daemon/bindings/net.c b/daemon/bindings/net.c index 440b809d..8906f5e2 100644 --- a/daemon/bindings/net.c +++ b/daemon/bindings/net.c @@ -49,7 +49,7 @@ static int net_list_add(const char *key, void *val, void *ext) lua_pushliteral(L, "unix"); break; default: - (void)!kr_assume(false); + kr_assert(false); lua_pushliteral(L, "invalid"); } lua_setfield(L, -2, "family"); @@ -79,7 +79,7 @@ static int net_list_add(const char *key, void *val, void *ext) } else if (ep->flags.sock_type == SOCK_DGRAM) { lua_pushliteral(L, "udp"); } else { - (void)!kr_assume(false); + kr_assert(false); lua_pushliteral(L, "invalid"); } lua_setfield(L, -2, "protocol"); @@ -108,7 +108,7 @@ static int net_list(lua_State *L) * \return success */ static bool net_listen_addrs(lua_State *L, int port, endpoint_flags_t flags, int16_t nic_queue) { - if (!kr_assume(flags.xdp || nic_queue == -1)) + if (kr_fails_assert(flags.xdp || nic_queue == -1)) return false; /* Case: table with 'addr' field; only follow that field directly. */ @@ -510,7 +510,7 @@ static int tls_params2lua(lua_State *L, trie_t *params) } else if (ia_len == 2 + sizeof(struct in6_addr)) { af = AF_INET6; } - if (!kr_assume(key && af != AF_UNSPEC)) + if (kr_fails_assert(key && af != AF_UNSPEC)) lua_error_p(L, "internal error: bad IP address"); uint16_t port; memcpy(&port, key, sizeof(port)); @@ -518,7 +518,7 @@ static int tls_params2lua(lua_State *L, trie_t *params) const char *ia = key + sizeof(port); char str[INET6_ADDRSTRLEN + 1 + 5 + 1]; size_t len = sizeof(str); - if (!kr_assume(kr_ntop_str(af, ia, port, str, &len) == kr_ok())) + if (kr_fails_assert(kr_ntop_str(af, ia, port, str, &len) == kr_ok())) lua_error_p(L, "internal error: bad IP address conversion"); /* ...and push it as [1]. */ lua_pushinteger(L, 1); @@ -526,7 +526,7 @@ static int tls_params2lua(lua_State *L, trie_t *params) lua_settable(L, -3); const tls_client_param_t *e = *trie_it_val(it); - if (!kr_assume(e)) + if (kr_fails_assert(e)) lua_error_p(L, "internal problem - NULL entry for %s", str); /* .hostname = */ @@ -553,7 +553,7 @@ static int tls_params2lua(lua_State *L, trie_t *params) uint8_t pin_base64[TLS_SHA256_BASE64_BUFLEN]; int err = kr_base64_encode(e->pins.at[i], TLS_SHA256_RAW_LEN, pin_base64, sizeof(pin_base64)); - if (!kr_assume(err >= 0)) + if (kr_fails_assert(err >= 0)) lua_error_p(L, "internal problem when converting pin_sha256: %s", kr_strerror(err)); @@ -687,7 +687,7 @@ static int net_tls_client(lua_State *L) ERROR("pin_sha256 is not a string"); uint8_t *pin_raw = malloc(TLS_SHA256_RAW_LEN); /* Push the string early to simplify error processing. */ - if (!kr_assume(pin_raw && array_push(newcfg->pins, pin_raw) >= 0)) { + if (kr_fails_assert(pin_raw && array_push(newcfg->pins, pin_raw) >= 0)) { free(pin_raw); ERROR("%s", kr_strerror(ENOMEM)); } @@ -943,7 +943,7 @@ static int net_outgoing(lua_State *L, int family) lua_pushnil(L); return 1; } - if (!kr_assume(addr->ip.sa_family == family)) + if (kr_fails_assert(addr->ip.sa_family == family)) lua_error_p(L, "bad address family"); char addr_buf[INET6_ADDRSTRLEN]; int err; |