From: Vladimír Čunát Date: Wed, 12 May 2021 17:03:37 +0000 (+0200) Subject: treewide: minor C11 cleanup X-Git-Tag: v5.4.0~18^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b58102322e2a68226fb7a770930f5e0caa13b11f;p=thirdparty%2Fknot-resolver.git treewide: minor C11 cleanup --- diff --git a/lib/cache/impl.h b/lib/cache/impl.h index 670361700..54b0802c1 100644 --- a/lib/cache/impl.h +++ b/lib/cache/impl.h @@ -303,7 +303,8 @@ static inline int rdataset_dematerialize_size(const knot_rdataset_t *rds) static inline int rdataset_dematerialized_size(const uint8_t *data, uint16_t *rdataset_count) { uint16_t count; - kr_require(sizeof(count) == KR_CACHE_RR_COUNT_SIZE); + static_assert(sizeof(count) == KR_CACHE_RR_COUNT_SIZE, + "Unexpected KR_CACHE_RR_COUNT_SIZE."); memcpy(&count, data, sizeof(count)); const uint8_t *rdata = data + sizeof(count); if (rdataset_count) // memcpy is safe for unaligned case (on non-x86) diff --git a/lib/defines.h b/lib/defines.h index dc8c37882..618903f46 100644 --- a/lib/defines.h +++ b/lib/defines.h @@ -26,10 +26,7 @@ #define KR_PRINTF(n) #endif -#ifndef uint /* Redefining typedef is a C11 feature. */ typedef unsigned int uint; -#define uint uint -#endif /* * Error codes. @@ -41,6 +38,10 @@ static inline int KR_COLD kr_error(int x) { } #define kr_strerror(x) strerror(abs(x)) +/* We require C11 but want to avoid including the standard assertion header + * so we alias it ourselves. */ +#define static_assert _Static_assert + /* * Connection limits. * @cond internal diff --git a/lib/utils.h b/lib/utils.h index e11e8b144..01b5c0506 100644 --- a/lib/utils.h +++ b/lib/utils.h @@ -154,11 +154,6 @@ void kr_log_q(const struct kr_query *qry, const char *source, const char *fmt, . knot_rrtype_to_string((rrtype), rrtype_str, sizeof(rrtype_str)); \ rrtype_str[sizeof(rrtype_str) - 1] = 0; -/* C11 compatibility, but without any implementation so far. */ -#ifndef static_assert -#define static_assert(cond, msg) -#endif - // Use this for alocations with mm. // Use mm_alloc for alocations into mempool