Commit a0aabdea authored by Vladimír Čunát's avatar Vladimír Čunát

Merge !702: CI clang-scan-build fixes

We had 35 reports, now we'll have just 7
and mostly in code that's not ours (contrib/*).
parents 1872d70c 19a3cad6
Pipeline #42585 failed with stages
in 101 minutes and 4 seconds
......@@ -38,7 +38,7 @@ enum {
SLOT_produce,
SLOT_checkout,
SLOT_answer_finalize,
SLOT_count
SLOT_count /* dummy, must be the last */
};
#define SLOT_size sizeof(int)
......@@ -107,13 +107,6 @@ static int l_ffi_init(struct kr_module *module)
return l_ffi_call(L, 1);
}
/** @internal Unregister layer callback reference from registry. */
#define LAYER_UNREGISTER(L, api, name) do { \
int *cb_slot = (int *)((char *)api + sizeof(kr_layer_api_t)); \
if (cb_slot[SLOT_ ## name] > 0) \
luaL_unref(L, LUA_REGISTRYINDEX, cb_slot[SLOT_ ## name]); \
} while(0)
static int l_ffi_deinit(struct kr_module *module)
{
/* Deinit the module in Lua (if possible) */
......@@ -122,32 +115,31 @@ static int l_ffi_deinit(struct kr_module *module)
if (l_ffi_preface(module, "deinit")) {
ret = l_ffi_call(L, 1);
}
module->lib = NULL;
/* Free the layer API wrapper (unconst it) */
kr_layer_api_t* api = module->data;
if (api) {
LAYER_UNREGISTER(L, api, begin);
LAYER_UNREGISTER(L, api, finish);
LAYER_UNREGISTER(L, api, consume);
LAYER_UNREGISTER(L, api, produce);
LAYER_UNREGISTER(L, api, checkout);
LAYER_UNREGISTER(L, api, answer_finalize);
LAYER_UNREGISTER(L, api, reset);
free(api);
if (!api) {
return ret;
}
module->lib = NULL;
/* Unregister layer callback references from registry. */
for (int si = 0; si < SLOT_count; ++si) {
if (api->cb_slots[si] > 0) {
luaL_unref(L, LUA_REGISTRYINDEX, api->cb_slots[si]);
}
}
free(api);
return ret;
}
#undef LAYER_UNREGISTER
/** @internal Helper for retrieving layer Lua function by name. */
#define LAYER_FFI_CALL(ctx, slot) \
int *cb_slot = (int *)((char *)(ctx)->api + sizeof(kr_layer_api_t)); \
if (cb_slot[SLOT_ ## slot] <= 0) { \
#define LAYER_FFI_CALL(ctx, slot_name) \
const int *cb_slot = (ctx)->api->cb_slots + SLOT_ ## slot_name; \
if (*cb_slot <= 0) { \
return ctx->state; \
} \
struct kr_module *module = (ctx)->api->data; \
lua_State *L = module->lib; \
lua_rawgeti(L, LUA_REGISTRYINDEX, cb_slot[SLOT_ ## slot]); \
lua_rawgeti(L, LUA_REGISTRYINDEX, *cb_slot); \
lua_pushnumber(L, ctx->state)
static int l_ffi_layer_begin(kr_layer_t *ctx)
......@@ -219,11 +211,11 @@ static int l_ffi_layer_answer_finalize(kr_layer_t *ctx)
/** @internal Conditionally register layer trampoline
* @warning Expects 'module.layer' to be on top of Lua stack. */
#define LAYER_REGISTER(L, api, name) do { \
int *cb_slot = (int *)((char *)api + sizeof(kr_layer_api_t)); \
int *cb_slot = (api)->cb_slots + SLOT_ ## name; \
lua_getfield((L), -1, #name); \
if (!lua_isnil((L), -1)) { \
(api)->name = l_ffi_layer_ ## name; \
cb_slot[SLOT_ ## name] = luaL_ref((L), LUA_REGISTRYINDEX); \
*cb_slot = luaL_ref((L), LUA_REGISTRYINDEX); \
} else { \
lua_pop((L), 1); \
} \
......@@ -234,7 +226,8 @@ static kr_layer_api_t *l_ffi_layer_create(lua_State *L, struct kr_module *module
{
/* Fabricate layer API wrapping the Lua functions
* reserve slots after it for references to Lua callbacks. */
const size_t api_length = sizeof(kr_layer_api_t) + (SLOT_count * SLOT_size);
const size_t api_length = offsetof(kr_layer_api_t, cb_slots)
+ (SLOT_count * SLOT_size);
kr_layer_api_t *api = malloc(api_length);
if (api) {
memset(api, 0, api_length);
......
......@@ -300,10 +300,7 @@ static struct request_ctx *request_create(struct worker_ctx *worker,
if (!addr || (addr->sa_family != AF_INET && addr->sa_family != AF_INET6)) {
ctx->source.addr.ip.sa_family = AF_UNSPEC;
} else {
size_t addr_len = sizeof(struct sockaddr_in);
if (addr->sa_family == AF_INET6)
addr_len = sizeof(struct sockaddr_in6);
memcpy(&ctx->source.addr.ip, addr, addr_len);
memcpy(&ctx->source.addr, addr, kr_sockaddr_len(addr));
ctx->req.qsource.addr = &ctx->source.addr.ip;
}
......@@ -1313,7 +1310,7 @@ static int tcp_task_step(struct qr_task *task,
subreq_finalize(task, packet_source, packet);
return qr_task_finalize(task, KR_STATE_FAIL);
}
int ret = kr_error(EINVAL);
int ret;
struct session* session = NULL;
if ((session = worker_find_tcp_waiting(ctx->worker, addr)) != NULL) {
/* Connection is in the list of waiting connections.
......
......@@ -41,7 +41,7 @@ int rdataset_dematerialize(const knot_rdataset_t *rds, uint8_t * restrict data)
data += size;
}
//VERBOSE_MSG(NULL, "dematerialized to %d B\n", (int)(data - data0));
//return data - data0;
(void)data;
return kr_ok();
}
......
......@@ -90,6 +90,9 @@ struct kr_layer_api {
/** The module can store anything in here. */
void *data;
/** Internal to ./daemon/ffimodule.c. */
int cb_slots[];
};
typedef struct kr_layer_api kr_layer_api_t;
......
......@@ -1031,7 +1031,6 @@ static int forward_trust_chain_check(struct kr_request *request, struct kr_query
return KR_STATE_PRODUCE;
}
const knot_dname_t *wanted_name = qry->sname;
const knot_dname_t *start_name = qry->sname;
if ((qry->flags.AWAIT_CUT) && !resume) {
qry->flags.AWAIT_CUT = false;
......@@ -1059,18 +1058,13 @@ static int forward_trust_chain_check(struct kr_request *request, struct kr_query
return KR_STATE_DONE;
}
bool nods = false;
bool ds_req = false;
bool ns_req = false;
bool ns_exist = true;
bool minimized = false;
int name_offset = 1;
const knot_dname_t *wanted_name;
bool nods, ds_req, ns_req, minimized, ns_exist;
do {
wanted_name = start_name;
nods = false;
ds_req = false;
ns_req = false;
minimized = false;
ns_exist = true;
int cut_labels = knot_dname_labels(qry->zone_cut.name, NULL);
......@@ -1089,11 +1083,7 @@ static int forward_trust_chain_check(struct kr_request *request, struct kr_query
knot_dname_is_equal(q->sname, wanted_name)) {
if (q->stype == KNOT_RRTYPE_DS) {
ds_req = true;
if (q->flags.DNSSEC_NODS) {
nods = true;
}
if (q->flags.CNAME) {
nods = true;
ns_exist = false;
} else if (!(q->flags.DNSSEC_OPTOUT)) {
int ret = kr_dnssec_matches_name_and_type(&request->auth_selected, q->uid,
......@@ -1102,7 +1092,6 @@ static int forward_trust_chain_check(struct kr_request *request, struct kr_query
}
} else {
if (q->flags.CNAME) {
nods = true;
ns_exist = false;
}
ns_req = true;
......@@ -1124,6 +1113,7 @@ static int forward_trust_chain_check(struct kr_request *request, struct kr_query
return KR_STATE_PRODUCE;
}
/* set `nods` */
if ((qry->stype == KNOT_RRTYPE_DS) &&
knot_dname_is_equal(wanted_name, qry->sname)) {
nods = true;
......
......@@ -424,27 +424,24 @@ void kr_inaddr_set_port(struct sockaddr *addr, uint16_t port)
int kr_inaddr_str(const struct sockaddr *addr, char *buf, size_t *buflen)
{
int ret = kr_ok();
if (!addr || !buf || !buflen) {
return kr_error(EINVAL);
}
char str[INET6_ADDRSTRLEN + 6];
if (!inet_ntop(addr->sa_family, kr_inaddr(addr), str, sizeof(str))) {
if (!inet_ntop(addr->sa_family, kr_inaddr(addr), buf, *buflen)) {
return kr_error(errno);
}
int len = strlen(str);
str[len] = '#';
u16tostr((uint8_t *)&str[len + 1], kr_inaddr_port(addr));
len += 6;
str[len] = 0;
if (len >= *buflen) {
ret = kr_error(ENOSPC);
} else {
memcpy(buf, str, len + 1);
const int len = strlen(buf);
const int len_need = len + 1 + 5 + 1;
if (len_need > *buflen) {
*buflen = len_need;
return kr_error(ENOSPC);
}
*buflen = len;
return ret;
*buflen = len_need;
buf[len] = '#';
u16tostr((uint8_t *)&buf[len + 1], kr_inaddr_port(addr));
buf[len_need - 1] = 0;
return kr_ok();
}
int kr_straddr_family(const char *addr)
......
......@@ -393,7 +393,7 @@ static inline char *kr_straddr(const struct sockaddr *addr)
{
assert(addr != NULL);
/* We are the sinle-threaded application */
static char str[INET6_ADDRSTRLEN + 6];
static char str[INET6_ADDRSTRLEN + 1 + 5 + 1];
size_t len = sizeof(str);
int ret = kr_inaddr_str(addr, str, &len);
return ret != kr_ok() || len == 0 ? NULL : str;
......
......@@ -9,15 +9,15 @@ set -o errexit -o nounset
# https://bugs.llvm.org/show_bug.cgi?id=3888
# These are disabled for other reasons:
# alpha.clone.CloneChecker # way too many false positives
# alpha.core.CastToStruct # we use this pattern too much, hard to avoid in many cases
# alpha.deadcode.UnreachableCode # false positives/flags sanity checks depending on implementation details
# alpha.security.MallocOverflow # not smart enough to infer max values from data types
# alpha.clone.CloneChecker # way too many false positives
${SCAN_BUILD:-scan-build} \
-disable-checker unix.Malloc \
-enable-checker alpha.core.BoolAssignment \
-enable-checker alpha.core.CallAndMessageUnInitRefArg \
-enable-checker alpha.core.CastToStruct \
-enable-checker alpha.core.CastSize \
-enable-checker alpha.core.Conversion \
-enable-checker alpha.core.DynamicTypeChecker \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment