From cfec3117d42a1e44feb76a13dc07be2b2e9799ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 17 Jul 2019 12:27:33 +0200 Subject: [PATCH 1/3] basic/macro: drop do {} while(0) from assert_not_reached log_assert_failed_unreachable is just a normal function call, no need to wrap it. https://github.com/systemd/systemd/issues/12997#issuecomment-510103988 --- src/basic/macro.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/basic/macro.h b/src/basic/macro.h index 81add201fa..fb002d2172 100644 --- a/src/basic/macro.h +++ b/src/basic/macro.h @@ -344,9 +344,7 @@ static inline int __coverity_check__(int condition) { #endif #define assert_not_reached(t) \ - do { \ - log_assert_failed_unreachable(t, PROJECT_FILE, __LINE__, __PRETTY_FUNCTION__); \ - } while (false) + log_assert_failed_unreachable(t, PROJECT_FILE, __LINE__, __PRETTY_FUNCTION__) #if defined(static_assert) #define assert_cc(expr) \ From ab1a1ba5dc80a7657fe09dcb4a614789d56538b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 17 Jul 2019 12:45:42 +0200 Subject: [PATCH 2/3] Drop trailing slash from assert_cc() definition We use assert_cc(...); almost everywhere. Let's always require that. https://github.com/systemd/systemd/issues/12997#issuecomment-510103988 --- src/basic/log.h | 2 +- src/basic/macro.h | 4 ++-- src/basic/process-util.h | 2 +- src/libsystemd-network/radv-internal.h | 2 +- src/resolve/resolved-dns-packet.c | 2 +- src/shared/json.h | 4 ++-- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/basic/log.h b/src/basic/log.h index 2e0179b2a5..625be22402 100644 --- a/src/basic/log.h +++ b/src/basic/log.h @@ -73,7 +73,7 @@ int log_get_max_level_realm(LogRealm realm) _pure_; * for the application itself. */ -assert_cc(STRLEN(__FILE__) > STRLEN(RELATIVE_SOURCE_PATH) + 1) +assert_cc(STRLEN(__FILE__) > STRLEN(RELATIVE_SOURCE_PATH) + 1); #define PROJECT_FILE (__FILE__ + STRLEN(RELATIVE_SOURCE_PATH) + 1) int log_open(void); diff --git a/src/basic/macro.h b/src/basic/macro.h index fb002d2172..00dfd48023 100644 --- a/src/basic/macro.h +++ b/src/basic/macro.h @@ -348,12 +348,12 @@ static inline int __coverity_check__(int condition) { #if defined(static_assert) #define assert_cc(expr) \ - static_assert(expr, #expr); + static_assert(expr, #expr) #else #define assert_cc(expr) \ struct CONCATENATE(_assert_struct_, __COUNTER__) { \ char x[(expr) ? 0 : -1]; \ - }; + } #endif #define assert_return(expr, r) \ diff --git a/src/basic/process-util.h b/src/basic/process-util.h index 4adf254808..41d4759c97 100644 --- a/src/basic/process-util.h +++ b/src/basic/process-util.h @@ -189,7 +189,7 @@ int set_oom_score_adjust(int value); #error "Unknown pid_t size" #endif -assert_cc(TASKS_MAX <= (unsigned long) PID_T_MAX) +assert_cc(TASKS_MAX <= (unsigned long) PID_T_MAX); /* Like TAKE_PTR() but for child PIDs, resetting them to 0 */ #define TAKE_PID(pid) \ diff --git a/src/libsystemd-network/radv-internal.h b/src/libsystemd-network/radv-internal.h index 517e4dc528..7b09c7a66c 100644 --- a/src/libsystemd-network/radv-internal.h +++ b/src/libsystemd-network/radv-internal.h @@ -11,7 +11,7 @@ #include "list.h" #include "sparse-endian.h" -assert_cc(SD_RADV_DEFAULT_MIN_TIMEOUT_USEC <= SD_RADV_DEFAULT_MAX_TIMEOUT_USEC) +assert_cc(SD_RADV_DEFAULT_MIN_TIMEOUT_USEC <= SD_RADV_DEFAULT_MAX_TIMEOUT_USEC); #define SD_RADV_MAX_INITIAL_RTR_ADVERT_INTERVAL_USEC (16*USEC_PER_SEC) #define SD_RADV_MAX_INITIAL_RTR_ADVERTISEMENTS 3 diff --git a/src/resolve/resolved-dns-packet.c b/src/resolve/resolved-dns-packet.c index 20ee8c9ca3..05aaa0fb7f 100644 --- a/src/resolve/resolved-dns-packet.c +++ b/src/resolve/resolved-dns-packet.c @@ -17,7 +17,7 @@ #define EDNS0_OPT_DO (1<<15) -assert_cc(DNS_PACKET_SIZE_START > DNS_PACKET_HEADER_SIZE) +assert_cc(DNS_PACKET_SIZE_START > DNS_PACKET_HEADER_SIZE); typedef struct DnsPacketRewinder { DnsPacket *packet; diff --git a/src/shared/json.h b/src/shared/json.h index d78082905a..1f9c620ebb 100644 --- a/src/shared/json.h +++ b/src/shared/json.h @@ -241,10 +241,10 @@ int json_dispatch_unsigned(const char *name, JsonVariant *variant, JsonDispatchF int json_dispatch_uint32(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata); int json_dispatch_int32(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata); -assert_cc(sizeof(uintmax_t) == sizeof(uint64_t)) +assert_cc(sizeof(uintmax_t) == sizeof(uint64_t)); #define json_dispatch_uint64 json_dispatch_unsigned -assert_cc(sizeof(intmax_t) == sizeof(int64_t)) +assert_cc(sizeof(intmax_t) == sizeof(int64_t)); #define json_dispatch_int64 json_dispatch_integer static inline int json_dispatch_level(JsonDispatchFlags flags) { From d268ab389c7a7532d52fecdd1d6ab99bce17e6a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 11 Jul 2019 10:17:28 +0200 Subject: [PATCH 3/3] Rewrite IN_SET() This restores proper speed with asan builds with gcc 9.1.1. Fixes #12997. $ rpm -q gcc gcc-9.1.1-2.fc31.x86_64 $ time ASAN_OPTIONS=strict_string_checks=1:detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1 UBSAN_OPTIONS=print_stacktrace=1:print_summary=1:halt_on_error=1 build-rawhide-sanitize/test-conf-parser (old) 86.99s user 20.22s system 361% cpu 29.635 total (new) 3.05s user 0.29s system 99% cpu 3.377 total Size is increased a bit: $ size build/systemd (old) 1683421 246100 1208 1930729 1d75e9 build/systemd (new) 1688237 246100 1208 1935545 1d88b9 build/systemd ... but that's <0.1%, so we don't really care. --- src/basic/macro.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/basic/macro.h b/src/basic/macro.h index 00dfd48023..336cb3a099 100644 --- a/src/basic/macro.h +++ b/src/basic/macro.h @@ -462,7 +462,8 @@ static inline int __coverity_check__(int condition) { * type for the array, in the hope that checkers such as ubsan don't complain that the initializers for \ * the array are not representable by the base type. Ideally we'd use typeof(x) as base type, but that \ * doesn't work, as we want to use this on bitfields and gcc refuses typeof() on bitfields.) */ \ - assert_cc((sizeof((long double[]){__VA_ARGS__})/sizeof(long double)) <= 20); \ + static const long double __assert_in_set[] _unused_ = { __VA_ARGS__ }; \ + assert_cc(ELEMENTSOF(__assert_in_set) <= 20); \ switch(x) { \ FOR_EACH_MAKE_CASE(__VA_ARGS__) \ _found = true; \