]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
lib/kru + elsewhere nit: avoid message-less static_assert()
authorVladimír Čunát <vladimir.cunat@nic.cz>
Tue, 25 Nov 2025 09:27:35 +0000 (10:27 +0100)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 1 Dec 2025 12:27:11 +0000 (13:27 +0100)
With clang they'd cause lots of complaints:
  warning: '_Static_assert' with no message is a C23 extension [-Wc23-extensions]

lib/cache/top.c
lib/kru.inc.c
utils/cache_gc/categories.c

index f9b7ace66431c7dbfec2164c6f6274404f37cbfc..363ffb2fe5ead5e2a713a4500c636bbef0f98e2a 100644 (file)
@@ -46,15 +46,15 @@ static inline uint32_t ticks_now(void)
 static inline bool first_access_ro(struct kr_cache_top_context *ctx, kru_hash_t hash)
 {
        // struct kr_cache_top_context { uint32_t bloom[32]; }
-       static_assert(sizeof(((struct kr_cache_top_context *)0)->bloom[0]) * 8 == 32);
-       static_assert(sizeof(((struct kr_cache_top_context *)0)->bloom)    * 8 == 32 * 32);
+       static_assert(sizeof(((struct kr_cache_top_context *)0)->bloom[0]) * 8 == 32, "");
+       static_assert(sizeof(((struct kr_cache_top_context *)0)->bloom)    * 8 == 32 * 32, "");
                // expected around 40 unique cache accesses per request context, possibly up to ~200;
                // prob. of collision of 50th unique access with the preceeding ones: ~0.1 %;
                // 75th: ~0.4 %; 100th: ~1.1 %; 150th: ~3.9 %; 200th: ~8.7 %; 300th: ~23 %; 400th: ~39 %
                //   -> collision means not counting the cache access in KRU while it should be
 
        uint8_t *h = (uint8_t *)&hash;
-       static_assert(sizeof(kru_hash_t) >= 8);
+       static_assert(sizeof(kru_hash_t) >= 8, "bad size of kru_hash_t");
 
        bool accessed = 1u &
                (ctx->bloom[h[0] % 32] >> (h[1] % 32)) &
@@ -70,7 +70,7 @@ static inline bool first_access(struct kr_cache_top_context *ctx, kru_hash_t has
        if (!first_access_ro(ctx, hash)) return false;
 
        uint8_t *h = (uint8_t *)&hash;
-       static_assert(sizeof(kru_hash_t) >= 8);
+       static_assert(sizeof(kru_hash_t) >= 8, "bad size of kru_hash_t");
 
        ctx->bloom[h[0] % 32] |= 1u << (h[1] % 32);
        ctx->bloom[h[2] % 32] |= 1u << (h[3] % 32);
index 162b1ab6d6d8ba1be979a7f768183f56e9f77b4f..cf23516b5f4a318a962e82815490c2e6e29fcdae 100644 (file)
@@ -268,7 +268,7 @@ static inline void kru_limited_prefetch(struct kru *kru, uint32_t time_now, uint
 {
        // Obtain hash of *buf.
        kru_hash_t hash;
-       static_assert(sizeof(kru_hash_t) * 8 <= 64);
+       static_assert(sizeof(kru_hash_t) * 8 <= 64, "bad size of kru_hash_t");
 #if !USE_AES
        hash = SipHash(&kru->hash_key, SIPHASH_RC, SIPHASH_RF, key, 16);
 #else
@@ -292,7 +292,7 @@ static inline void kru_limited_prefetch_prefix(struct kru *kru, uint32_t time_no
 {
        // Obtain hash of *buf.
        kru_hash_t hash;
-       static_assert(sizeof(kru_hash_t) * 8 <= 64);
+       static_assert(sizeof(kru_hash_t) * 8 <= 64, "bad size of kru_hash_t");
 
 #if !USE_AES
        {
@@ -354,10 +354,10 @@ static kru_hash_t kru_hash_bytes(struct kru *kru, uint8_t *key, size_t key_size)
 {
        // Obtain hash of *buf.
        kru_hash_t hash;
-       static_assert(sizeof(kru_hash_t) * 8 <= 64);
+       static_assert(sizeof(kru_hash_t) * 8 <= 64, "bad size of kru_hash_t");
 
        // We use SipHash even for otherwise optimized KRU variant, which has diffent type of hash_key.
-       static_assert(sizeof(kru->hash_key) >= sizeof(SIPHASH_KEY));
+       static_assert(sizeof(kru->hash_key) >= sizeof(SIPHASH_KEY), "bad size of kru::hash_key");
        SIPHASH_KEY *hash_key = (void *)&kru->hash_key;
 
        hash = SipHash(hash_key, SIPHASH_RC, SIPHASH_RF, key, key_size);
index 579320a2bf08b51f130007c077309884a81ca119..f54fc5d84c0f9fd2b9de9ed0a14cf01d418a019a 100644 (file)
@@ -34,7 +34,7 @@ category_t kr_gc_categorize(struct kr_cache_top *top, gc_record_info_t * info, v
                // evict all expired before any non-expired (incl. RTT)
                res = res / 2 + 65;  // 65..97
        }
-       static_assert(CATEGORIES - 1 > 97);
+       static_assert(CATEGORIES - 1 > 97, "inssuficient CATEGORIES number");
 
        if (!kr_log_is_debug(CACHE, NULL)) // skip these computations if not needed
                goto finish;