summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOto Šťáva <oto.stava@nic.cz>2024-05-29 16:04:45 +0200
committerOto Šťáva <oto.stava@nic.cz>2024-06-04 13:05:00 +0200
commita805ad6355812ed21669ca99ebb28cff245e7374 (patch)
tree0be7a9f981f6459db1cc52ffffa37e299777e27c
parentdaemon/session2: optimize allocations (diff)
downloadknot-resolver-a805ad6355812ed21669ca99ebb28cff245e7374.tar.xz
knot-resolver-a805ad6355812ed21669ca99ebb28cff245e7374.zip
Some more Clang-Tidy silencing
-rw-r--r--.clang-tidy84
-rw-r--r--daemon/session2.h2
-rw-r--r--daemon/tls.c5
-rw-r--r--lib/rules/api.c12
-rw-r--r--lib/rules/local-addr.c2
-rw-r--r--lib/rules/zonefile.c3
6 files changed, 61 insertions, 47 deletions
diff --git a/.clang-tidy b/.clang-tidy
index ecc9a621..bc1d69c3 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -1,43 +1,51 @@
---
-Checks:
- - bugprone-*
- - cert-*
- - google-readability-casting
- - misc-*
- - readability-*
+Checks: |-
+ bugprone-*,
+ cert-*,
+ google-readability-casting,
+ misc-*,
+ readability-*,
- - -bugprone-assignment-in-if-condition # we explicitly put assignments into parentheses so they are very visible
- - -bugprone-branch-clone
- - -bugprone-easily-swappable-parameters
- - -bugprone-inc-dec-in-conditions
- - -bugprone-multi-level-implicit-pointer-conversion
- - -bugprone-narrowing-conversions
- - -bugprone-sizeof-expression # may be useful, but it's utterly broken
- - -bugprone-suspicious-string-compare
- - -cert-dcl03-c
- - -clang-analyzer-deadcode.DeadStores
- - -clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling
- - -clang-analyzer-unix.Malloc
- - -clang-analyzer-valist.Uninitialized
- - -clang-analyzer-optin.core.EnumCastOutOfRange # libknot uses enums as flags
- - -misc-include-cleaner
- - -misc-macro-parentheses
- - -misc-no-recursion
- - -misc-static-assert
- - -misc-unused-parameters
- - -readability-avoid-nested-conditional-operator
- - -readability-avoid-unconditional-preprocessor-if
- - -readability-braces-*
- - -readability-cognitive-complexity
- - -readability-else-after-return
- - -readability-function-cognitive-complexity
- - -readability-identifier-length
- - -readability-isolate-declaration
- - -readability-magic-numbers
- - -readability-non-const-parameter
- - -readability-redundant-declaration
-WarningsAsErrors: 'cert-*,clang-analyzer-*,misc-*,readability-*,-readability-non-const-parameter'
-HeaderFilterRegex: 'contrib/ucw/*.h'
+ -bugprone-assignment-in-if-condition,
+ -bugprone-branch-clone,
+ -bugprone-easily-swappable-parameters,
+ -bugprone-inc-dec-in-conditions,
+ -bugprone-multi-level-implicit-pointer-conversion,
+ -bugprone-narrowing-conversions,
+ -bugprone-not-null-terminated-result,
+ -bugprone-sizeof-expression,
+ -bugprone-suspicious-string-compare,
+ -cert-dcl03-c,
+ -clang-analyzer-deadcode.DeadStores,
+ -clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,
+ -clang-analyzer-unix.Malloc,
+ -clang-analyzer-valist.Uninitialized,
+ -clang-analyzer-optin.core.EnumCastOutOfRange,
+ -misc-include-cleaner,
+ -misc-macro-parentheses,
+ -misc-no-recursion,
+ -misc-static-assert,
+ -misc-unused-parameters,
+ -readability-avoid-nested-conditional-operator,
+ -readability-avoid-unconditional-preprocessor-if,
+ -readability-braces-*,
+ -readability-cognitive-complexity,
+ -readability-else-after-return,
+ -readability-function-cognitive-complexity,
+ -readability-identifier-length,
+ -readability-isolate-declaration,
+ -readability-magic-numbers,
+ -readability-non-const-parameter,
+ -readability-redundant-declaration,
+
+WarningsAsErrors: |-
+ cert-*,
+ clang-analyzer-*,
+ misc-*,
+ readability-*,
+ -readability-non-const-parameter,
+
+HeaderFilterRegex: '(contrib/ucw/*.h|/usr/*.h)'
CheckOptions:
- key: readability-identifier-naming
value: 'lower_case'
diff --git a/daemon/session2.h b/daemon/session2.h
index ada57af2..b43d8fc1 100644
--- a/daemon/session2.h
+++ b/daemon/session2.h
@@ -854,7 +854,7 @@ struct session2 {
* individual layer implementations to determine the lifetime of the data
* pointed to by the parameters. */
struct session2 *session2_new(enum session2_transport_type transport_type,
- enum kr_proto layer_grp,
+ enum kr_proto proto,
struct protolayer_data_param *layer_param,
size_t layer_param_count,
bool outgoing);
diff --git a/daemon/tls.c b/daemon/tls.c
index 90271bc8..a5169ae3 100644
--- a/daemon/tls.c
+++ b/daemon/tls.c
@@ -218,6 +218,11 @@ static ssize_t kres_gnutls_vec_push(gnutls_transport_ptr_t h, const giovec_t * i
return 0;
}
+ if (kr_fails_assert(iovcnt > 0)) {
+ errno = EINVAL;
+ return -1;
+ }
+
size_t total_len = 0;
for (int i = 0; i < iovcnt; i++)
total_len += iov[i].iov_len;
diff --git a/lib/rules/api.c b/lib/rules/api.c
index c10cbb0b..8e908a7a 100644
--- a/lib/rules/api.c
+++ b/lib/rules/api.c
@@ -158,7 +158,7 @@ int kr_rules_init(const char *path, size_t maxsize)
// Later we might improve it to auto-resize in case of running out of space.
// Caveat: mdb_env_set_mapsize() can only be called without transactions open.
.maxsize = maxsize ? maxsize :
- (sizeof(size_t) > 4 ? 2048 : 500) * 1024*(size_t)1024,
+ (size_t)(sizeof(size_t) > 4 ? 2048 : 500) * 1024*1024,
};
int ret = the_rules->api->open(&the_rules->db, &the_rules->stats, &opts, NULL);
/* No persistence - we always refill from config for now.
@@ -848,8 +848,8 @@ static int subnet_encode(const struct sockaddr *addr, int sub_len, uint8_t buf[3
uint16_t x = a[i] * 85; // interleave by zero bits
uint8_t sub_mask = 255 >> (8 - MIN(sub_len, 8));
uint16_t r = x | (sub_mask * 85 * 2);
- buf[2*i] = r / 256;
- buf[2*i + 1] = r % 256;
+ buf[(ssize_t)2*i] = r / 256;
+ buf[(ssize_t)2*i + 1] = r % 256;
}
return i * 2;
}
@@ -870,9 +870,9 @@ bool subnet_is_prefix(uint8_t a, uint8_t b)
}
#define KEY_PREPEND(key, arr) do { \
- key.data -= sizeof(arr); \
- key.len += sizeof(arr); \
- memcpy(key.data, arr, sizeof(arr)); \
+ (key).data -= sizeof(arr); \
+ (key).len += sizeof(arr); \
+ memcpy((key).data, arr, sizeof(arr)); \
} while (false)
int kr_view_insert_action(const char *subnet, const char *dst_subnet,
diff --git a/lib/rules/local-addr.c b/lib/rules/local-addr.c
index 787639df..cd5d456b 100644
--- a/lib/rules/local-addr.c
+++ b/lib/rules/local-addr.c
@@ -67,7 +67,7 @@ static const knot_dname_t * raw_addr2reverse(const uint8_t *raw_addr, int family
#undef REV_MAXLEN
if (family == AF_INET) {
- snprintf(reverse_addr, sizeof(reverse_addr),
+ (void)snprintf(reverse_addr, sizeof(reverse_addr),
"%d.%d.%d.%d.in-addr.arpa.",
raw_addr[3], raw_addr[2], raw_addr[1], raw_addr[0]);
} else if (family == AF_INET6) {
diff --git a/lib/rules/zonefile.c b/lib/rules/zonefile.c
index 74a7317d..d308f375 100644
--- a/lib/rules/zonefile.c
+++ b/lib/rules/zonefile.c
@@ -203,6 +203,7 @@ static void process_record(zs_scanner_t *s)
KR_RRTYPE_GET_STR(type_str, s->r_type);
kr_log_warning(RULES, "skipping unsupported RR type %s\n", type_str);
return;
+ default:; // Continue below
}
if (knot_rrtype_is_metatype(s->r_type))
goto unsupported_type;
@@ -245,7 +246,7 @@ int kr_rule_zonefile(const struct kr_rule_zonefile_config *c)
s_data_t s_data = { 0 };
s_data.c = c;
- s_data.pool = mm_ctx_mempool2(64 * 1024);
+ s_data.pool = mm_ctx_mempool2((size_t)64 * 1024);
s_data.rrs = trie_create(s_data.pool);
ret = zs_set_processing(s, process_record, NULL, &s_data);
if (kr_fails_assert(ret == 0))