Commit 2d9d9f90 authored by Daniel Salzman's avatar Daniel Salzman

Add -Wshadow to default CFLAGS + adapt code

parent be10afd0
......@@ -45,7 +45,7 @@ AM_PROG_CC_C_O
AC_PROG_CPP_WERROR
# Set default CFLAGS
CFLAGS="$CFLAGS -Wall -Werror=format-security -Werror=implicit -Wstrict-prototypes"
CFLAGS="$CFLAGS -Wall -Wshadow -Werror=format-security -Werror=implicit -Wstrict-prototypes"
AX_CHECK_COMPILE_FLAG("-fpredictive-commoning", [CFLAGS="$CFLAGS -fpredictive-commoning"], [], "-Werror")
AX_CHECK_LINK_FLAG(["-Wl,--exclude-libs,ALL"], [ldflag_exclude_libs="-Wl,--exclude-libs,ALL"], [ldflag_exclude_libs=""], "")
......
......@@ -233,8 +233,8 @@ static int db_code(
conf->api->iter_finish(it);
return ret;
}
uint8_t code = ((uint8_t *)iter_val.data)[0];
codes[code] = true;
uint8_t used_code = ((uint8_t *)iter_val.data)[0];
codes[used_code] = true;
it = conf->api->iter_next(it);
}
......
......@@ -616,13 +616,13 @@ static int fix_nsec3_for_node(zone_update_t *update, const dnssec_nsec3_params_t
if (new_nsec3_n == NULL) {
return KNOT_ENOMEM;
}
knot_rrset_t add_nsec3 = node_rrset(new_nsec3_n, KNOT_RRTYPE_NSEC3);
assert(!knot_rrset_empty(&add_nsec3));
knot_rrset_t nsec3 = node_rrset(new_nsec3_n, KNOT_RRTYPE_NSEC3);
assert(!knot_rrset_empty(&nsec3));
// copy hash of next element from removed record
if (next_hash != NULL) {
uint8_t *raw_hash = (uint8_t *)knot_nsec3_next(add_nsec3.rrs.rdata);
uint8_t raw_length = knot_nsec3_next_len(add_nsec3.rrs.rdata);
uint8_t *raw_hash = (uint8_t *)knot_nsec3_next(nsec3.rrs.rdata);
uint8_t raw_length = knot_nsec3_next_len(nsec3.rrs.rdata);
assert(raw_hash != NULL);
if (raw_length != next_length) {
ret = KNOT_EMALF;
......@@ -632,9 +632,9 @@ static int fix_nsec3_for_node(zone_update_t *update, const dnssec_nsec3_params_t
}
if (ret == KNOT_EOK) {
if (next_hash == NULL) {
ret = zone_update_add(update, &add_nsec3);
ret = zone_update_add(update, &nsec3);
} else {
ret = changeset_add_addition(chgset, &add_nsec3, CHANGESET_CHECK | CHANGESET_CHECK_CANCELOUT);
ret = changeset_add_addition(chgset, &nsec3, CHANGESET_CHECK | CHANGESET_CHECK_CANCELOUT);
}
}
node_free_rrsets(new_nsec3_n, NULL);
......
......@@ -362,7 +362,7 @@ int knot_zone_create_nsec_chain(zone_update_t *update,
goto cleanup;
}
} else {
int ret = knot_nsec_create_chain(update->new_cont, nsec_ttl, &ch);
ret = knot_nsec_create_chain(update->new_cont, nsec_ttl, &ch);
if (ret != KNOT_EOK) {
goto cleanup;
}
......
......@@ -1438,12 +1438,12 @@ static int store_changesets(journal_t *j, list_t *changesets)
// PART 4: continuity and duplicity check
changeset_t * chs_head = (HEAD(*changesets));
bool is_first_bootstrap = (chs_head->soa_from == NULL);
uint32_t serial = is_first_bootstrap ? 0 : knot_soa_serial(chs_head->soa_from->rrs.rdata);
uint32_t first_serial = is_first_bootstrap ? 0 : knot_soa_serial(chs_head->soa_from->rrs.rdata);
if (md_flag(txn, SERIAL_TO_VALID) && (is_first_bootstrap ||
!serial_equal(txn->shadow_md.last_serial_to, serial)) &&
!serial_equal(txn->shadow_md.last_serial_to, first_serial)) &&
!inserting_bootstrap /* if inserting bootstrap, drop_journal() was called, so no discontinuity */) {
log_zone_warning(j->zone, "journal, discontinuity in changes history (%u -> %u), dropping older changesets",
txn->shadow_md.last_serial_to, serial);
txn->shadow_md.last_serial_to, first_serial);
if (zone_in_journal) {
txn->ret = KNOT_ERANGE; // we can't drop history if zone-in-journal, so this is forbidden
goto store_changeset_cleanup;
......
......@@ -278,8 +278,8 @@ static int follow_cname(knot_pkt_t *pkt, uint16_t rrtype, knotd_qdata_t *qdata)
qdata->rcode = KNOT_RCODE_YXDOMAIN;
} else {
knot_rrset_t dname_rr = cname_rr;
int ret = dname_cname_synth(&dname_rr, qdata->name,
&cname_rr, &pkt->mm);
ret = dname_cname_synth(&dname_rr, qdata->name,
&cname_rr, &pkt->mm);
if (ret != KNOT_EOK) {
qdata->rcode = KNOT_RCODE_SERVFAIL;
return KNOTD_IN_STATE_ERROR;
......
......@@ -385,19 +385,19 @@ static int prepare_answer(knot_pkt_t *query, knot_pkt_t *resp, knot_layer_t *ctx
if (has_limit) {
resp->max_size = KNOT_WIRE_MIN_PKTSIZE;
if (knot_pkt_has_edns(query)) {
uint16_t server;
uint16_t server_size;
switch (qdata->params->remote->ss_family) {
case AF_INET:
server = conf()->cache.srv_max_ipv4_udp_payload;
server_size = conf()->cache.srv_max_ipv4_udp_payload;
break;
case AF_INET6:
server = conf()->cache.srv_max_ipv6_udp_payload;
server_size = conf()->cache.srv_max_ipv6_udp_payload;
break;
default:
return KNOT_ERROR;
}
uint16_t client = knot_edns_get_payload(query->opt_rr);
uint16_t transfer = MIN(client, server);
uint16_t client_size = knot_edns_get_payload(query->opt_rr);
uint16_t transfer = MIN(client_size, server_size);
resp->max_size = MAX(resp->max_size, transfer);
}
} else {
......
......@@ -46,9 +46,9 @@ static int free_additional(zone_node_t **node, void *data)
UNUSED(data);
for (uint16_t i = 0; i < (*node)->rrset_count; ++i) {
struct rr_data *data = &(*node)->rrs[i];
additional_clear(data->additional);
data->additional = NULL;
struct rr_data *rrdata = &(*node)->rrs[i];
additional_clear(rrdata->additional);
rrdata->additional = NULL;
}
return KNOT_EOK;
......
......@@ -708,7 +708,7 @@ static int recreate_normal_tree(const zone_contents_t *z, zone_contents_t *out)
return KNOT_ENOMEM;
}
int ret = add_node(out, to_add, true);
ret = add_node(out, to_add, true);
if (ret != KNOT_EOK) {
node_free(to_add, NULL);
trie_it_free(itt);
......
......@@ -502,7 +502,7 @@ int yp_addr_to_txt(
// Write port.
wire_ctx_skip(in, -sizeof(uint64_t));
int ret = yp_int_to_txt(in, out, YP_SNONE);
ret = yp_int_to_txt(in, out, YP_SNONE);
if (ret != KNOT_EOK) {
return ret;
}
......
......@@ -336,7 +336,7 @@ int net_connect(net_t *net)
// Establish TLS connection.
if (net->tls.params != NULL) {
int ret = tls_ctx_connect(&net->tls, sockfd, net->tls.params->sni);
ret = tls_ctx_connect(&net->tls, sockfd, net->tls.params->sni);
if (ret != KNOT_EOK) {
close(sockfd);
return ret;
......
......@@ -742,8 +742,7 @@ static int process_query_packet(const knot_pkt_t *query,
const uint8_t *data = knot_edns_opt_get_data(opt);
uint16_t data_len = knot_edns_opt_get_length(opt);
int ret = knot_edns_cookie_parse(&new_ctx.cc, &new_ctx.sc,
data, data_len);
ret = knot_edns_cookie_parse(&new_ctx.cc, &new_ctx.sc, data, data_len);
if (ret != KNOT_EOK) {
knot_pkt_free(reply);
ERR("bad cookie, missing EDNS cookie option\n");
......
......@@ -102,15 +102,15 @@ static void print_help(void)
PROGRAM_NAME, PROGRAM_NAME, PROGRAM_NAME, CONF_DEFAULT_FILE, CONF_DEFAULT_DBDIR);
}
static int key_command(int argc, char *argv[], int optind)
static int key_command(int argc, char *argv[], int opt_ind)
{
if (argc < optind + 2) {
if (argc < opt_ind + 2) {
printf("Zone name and/or command not specified\n");
print_help();
return KNOT_EINVAL;
}
argc -= optind;
argv += optind;
argc -= opt_ind;
argv += opt_ind;
knot_dname_t *zone_name = knot_dname_from_str_alloc(argv[0]);
if (zone_name == NULL) {
......
......@@ -354,7 +354,7 @@ static char *prompt(EditLine *el)
return PROGRAM_NAME"> ";
}
int interactive_loop(params_t *params)
int interactive_loop(params_t *process_params)
{
char *hist_file = NULL;
const char *home = getenv("HOME");
......@@ -412,7 +412,7 @@ int interactive_loop(params_t *params)
}
// Process the command.
ret = process_cmd(argc, argv, params);
ret = process_cmd(argc, argv, process_params);
history(hist, &hev, H_SAVE, hist_file);
tok_reset(tok);
......
......@@ -209,11 +209,12 @@ static void test_conf_io_abort(void)
SKIP_OPENBSD
#else
// Test child persistence after subchild abort.
ok(conf_io_begin(false) == KNOT_EOK, "begin parent txn");
char idx[2] = { '0' };
ok(conf_io_set("server", "version", NULL, idx) ==
KNOT_EOK, "set single value '%s'", idx);
{
char idx[2] = { '0' };
ok(conf_io_begin(false) == KNOT_EOK, "begin parent txn");
ok(conf_io_set("server", "version", NULL, idx) ==
KNOT_EOK, "set single value '%s'", idx);
}
for (int i = 1; i < CONF_MAX_TXN_DEPTH; i++) {
char idx[2] = { '0' + i };
......@@ -265,11 +266,12 @@ static void test_conf_io_commit(void)
SKIP_OPENBSD
#else
// Test subchild persistence after commit.
ok(conf_io_begin(false) == KNOT_EOK, "begin parent txn");
char idx[2] = { '0' };
ok(conf_io_set("server", "version", NULL, idx) ==
KNOT_EOK, "set single value '%s'", idx);
{
char idx[2] = { '0' };
ok(conf_io_begin(false) == KNOT_EOK, "begin parent txn");
ok(conf_io_set("server", "version", NULL, idx) ==
KNOT_EOK, "set single value '%s'", idx);
}
for (int i = 1; i < CONF_MAX_TXN_DEPTH; i++) {
char idx[2] = { '0' + i };
......@@ -294,7 +296,7 @@ static void test_conf_io_commit(void)
ok(conf_io_begin(false) == KNOT_EOK, "begin new parent txn");
conf_val_t val = conf_get_txn(conf(), conf()->io.txn, C_SERVER, C_VERSION);
ok(val.code == KNOT_EOK, "check entry");
idx[0] = '0' + CONF_MAX_TXN_DEPTH - 1;
char idx[2] = { '0' + CONF_MAX_TXN_DEPTH - 1 };
const char *data = conf_str(&val);
ok(strcmp(data, idx) == 0, "compare final data '%s'", data);
conf_io_abort(false);
......
......@@ -38,9 +38,8 @@
char *test_dir_name;
journal_db_t *db;
journal_t *j;
const knot_dname_t *apex = (const uint8_t *)"\4test";
static void set_conf(int zonefile_sync, size_t journal_usage)
static void set_conf(int zonefile_sync, size_t journal_usage, const knot_dname_t *apex)
{
char conf_str[512];
snprintf(conf_str, sizeof(conf_str),
......@@ -267,11 +266,11 @@ static void test_journal_db(void)
}
/*! \brief Test behavior with real changesets. */
static void test_store_load(void)
static void test_store_load(const knot_dname_t *apex)
{
int ret, ret2 = KNOT_EOK;
set_conf(1000, 512 * 1024);
set_conf(1000, 512 * 1024, apex);
j = journal_new();
ok(j != NULL, "journal: new");
......@@ -613,13 +612,13 @@ static int merged_present(void)
return res;
}
static void test_merge(void)
static void test_merge(const knot_dname_t *apex)
{
int i, ret;
list_t l;
// allow merge
set_conf(-1, 512 * 1024);
set_conf(-1, 512 * 1024, apex);
ok(journal_merge_allowed(j), "journal: merge allowed");
ret = drop_journal(j, NULL);
......@@ -657,7 +656,7 @@ static void test_merge(void)
// disallow merge
unset_conf();
set_conf(1000, 512 * 1024);
set_conf(1000, 512 * 1024, apex);
ok(!journal_merge_allowed(j), "journal: merge disallowed");
tm_rrs(NULL, 0);
......@@ -665,22 +664,23 @@ static void test_merge(void)
unset_conf();
}
static void test_stress_base(journal_t *j, size_t update_size, size_t file_size)
static void test_stress_base(journal_t *journal, const knot_dname_t *apex,
size_t update_size, size_t file_size)
{
int ret;
uint32_t serial = 0;
journal_close(j);
journal_close(journal);
journal_db_close(&db);
db = NULL;
ret = journal_db_init(&db, test_dir_name, file_size, JOURNAL_MODE_ASYNC);
assert(ret == KNOT_EOK);
ret = journal_open_db(&db);
assert(ret == KNOT_EOK);
ret = journal_open(j, &db, apex);
ret = journal_open(journal, &db, apex);
assert(ret == KNOT_EOK);
set_conf(1000, file_size / 2);
set_conf(1000, file_size / 2, apex);
changeset_t ch;
ret = changeset_init(&ch, apex);
......@@ -691,7 +691,7 @@ static void test_stress_base(journal_t *j, size_t update_size, size_t file_size)
serial = 0;
while (true) {
changeset_set_soa_serials(&ch, serial, serial + 1, apex);
ret = journal_store_changeset(j, &ch);
ret = journal_store_changeset(journal, &ch);
if (ret == KNOT_EOK) {
serial++;
} else {
......@@ -699,7 +699,7 @@ static void test_stress_base(journal_t *j, size_t update_size, size_t file_size)
}
}
int ret = journal_flush(j);
ret = journal_flush(journal);
ok(serial > 0 && ret == KNOT_EOK, "journal: pass #%d fillup run (%d inserts)", i, serial);
}
......@@ -709,31 +709,33 @@ static void test_stress_base(journal_t *j, size_t update_size, size_t file_size)
}
/*! \brief Test behavior when writing to jurnal and flushing it. */
static void test_stress(journal_t *j)
static void test_stress(journal_t *journal, const knot_dname_t *apex)
{
diag("stress test: small data");
test_stress_base(j, 40, (1024 + 512) * 1024);
test_stress_base(journal, apex, 40, (1024 + 512) * 1024);
diag("stress test: medium data");
test_stress_base(j, 400, 3 * 1024 * 1024);
test_stress_base(journal, apex, 400, 3 * 1024 * 1024);
diag("stress test: large data");
test_stress_base(j, 4000, 10 * 1024 * 1024);
test_stress_base(journal, apex, 4000, 10 * 1024 * 1024);
}
int main(int argc, char *argv[])
{
plan_lazy();
const knot_dname_t *apex = (const uint8_t *)"\4test";
test_dir_name = test_mkdtemp();
test_journal_db();
test_store_load();
test_store_load(apex);
test_merge();
test_merge(apex);
test_stress(j);
test_stress(j, apex);
journal_close(j);
journal_free(&j);
......
......@@ -36,13 +36,12 @@ static const char *node_str2 = "node.test. IN TXT \"def\"\n";
knot_rrset_t rrset;
/*!< \brief Returns true if node contains given RR in its RRSets. */
static bool node_contains_rr(const zone_node_t *node,
const knot_rrset_t *rrset)
static bool node_contains_rr(const zone_node_t *node, const knot_rrset_t *data)
{
const knot_rdataset_t *zone_rrs = node_rdataset(node, rrset->type);
const knot_rdataset_t *zone_rrs = node_rdataset(node, data->type);
if (zone_rrs != NULL) {
knot_rdata_t *rr = rrset->rrs.rdata;
for (size_t i = 0; i < rrset->rrs.count; ++i) {
knot_rdata_t *rr = data->rrs.rdata;
for (size_t i = 0; i < data->rrs.count; ++i) {
if (!knot_rdataset_member(zone_rrs, rr)) {
return false;
}
......
......@@ -27,7 +27,7 @@
#define check_attr_scalar(key, type, name, def_val, set_val) { \
type value = dnssec_key_get_##name(key); \
ok(value == def_val, #name " default"); \
int r = dnssec_key_set_##name(key, set_val); \
r = dnssec_key_set_##name(key, set_val); \
ok(r == DNSSEC_EOK, #name " set"); \
value = dnssec_key_get_##name(key); \
ok(value == set_val, #name " get"); \
......
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