From 14899e2ba367d181f0a41d36a446a8558e90edea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 4 Jan 2018 13:27:51 +0100 Subject: [PATCH 1/2] test-routing-policy-rule: split out fd assignment from assert_se It's ugly that parentheses need to be used. Let's just split it out. Incidentally, this will make coverity happy, because it doesn't grok assert_se(). --- src/network/test-routing-policy-rule.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/network/test-routing-policy-rule.c b/src/network/test-routing-policy-rule.c index c29d134de2..3bbdd25b76 100644 --- a/src/network/test-routing-policy-rule.c +++ b/src/network/test-routing-policy-rule.c @@ -41,13 +41,15 @@ static void test_rule_serialization(const char *title, const char *ruleset, cons log_info("========== %s ==========", title); log_info("put:\n%s\n", ruleset); - assert_se((fd = mkostemp_safe(pattern)) >= 0); + fd = mkostemp_safe(pattern); + assert_se(fd >= 0); assert_se(f = fdopen(fd, "a+e")); assert_se(write_string_stream(f, ruleset, 0) == 0); assert_se(routing_policy_load_rules(pattern, &rules) == 0); - assert_se((fd2 = mkostemp_safe(pattern2)) >= 0); + fd2 = mkostemp_safe(pattern2); + assert_se(fd2 >= 0); assert_se(f2 = fdopen(fd2, "a+e")); assert_se(routing_policy_serialize_rules(rules, f2) == 0); @@ -57,7 +59,8 @@ static void test_rule_serialization(const char *title, const char *ruleset, cons log_info("got:\n%s", buf); - assert_se((fd3 = mkostemp_safe(pattern3)) >= 0); + fd3 = mkostemp_safe(pattern3); + assert_se(fd3 >= 0); assert_se(f3 = fdopen(fd3, "we")); assert_se(write_string_stream(f3, expected ?: ruleset, 0) == 0); From 963c6c90af87fdf8b7dcb942991fb018b87fea07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 4 Jan 2018 09:45:23 +0100 Subject: [PATCH 2/2] coverity: don't use (void)0 under coverity I'm not sure why this is needed, but apparrently coverity doesn't like (void)0. With this change, coverity can (almost) build systemd: CFLAGS='-D_Float128="long double"' meson cov-build -Dman=false && \ CCACHE_DISABLE=1 COVERITY_UNSUPPORTED=1 cov-build --dir cov-int ninja -C cov-build Patch originially by Marek Cermak . --- src/basic/macro.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/basic/macro.h b/src/basic/macro.h index 02d22de833..89bdd852a9 100644 --- a/src/basic/macro.h +++ b/src/basic/macro.h @@ -139,11 +139,17 @@ static inline unsigned long ALIGN_POWER2(unsigned long u) { return 1UL << (sizeof(u) * 8 - __builtin_clzl(u - 1UL)); } +#ifndef __COVERITY__ +# define VOID_0 ((void)0) +#else +# define VOID_0 ((void*)0) +#endif + #define ELEMENTSOF(x) \ __extension__ (__builtin_choose_expr( \ !__builtin_types_compatible_p(typeof(x), typeof(&*(x))), \ sizeof(x)/sizeof((x)[0]), \ - (void)0)) + VOID_0)) /* * STRLEN - return the length of a string literal, minus the trailing NUL byte. @@ -181,7 +187,7 @@ static inline unsigned long ALIGN_POWER2(unsigned long u) { __builtin_constant_p(_B) && \ __builtin_types_compatible_p(typeof(_A), typeof(_B)), \ ((_A) > (_B)) ? (_A) : (_B), \ - (void)0)) + VOID_0)) /* takes two types and returns the size of the larger one */ #define MAXSIZE(A, B) (sizeof(union _packed_ { typeof(A) a; typeof(B) b; }))