From 6923020ec12152ec9804d483de97284c970c7de3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 9 Jun 2021 12:23:07 +0200 Subject: [PATCH 1/4] networkd: reorder conditional to handle errors first This also avoid the implicit assumption that if r is not -ENOENT, 0, or 1, it must be negative. The compiler cannot know this. --- src/network/networkd-routing-policy-rule.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/network/networkd-routing-policy-rule.c b/src/network/networkd-routing-policy-rule.c index a319a6fbe3..39b773fcc0 100644 --- a/src/network/networkd-routing-policy-rule.c +++ b/src/network/networkd-routing-policy-rule.c @@ -338,7 +338,9 @@ static int routing_policy_rule_add(Manager *m, const RoutingPolicyRule *in, Rout rule->manager = m; existing = TAKE_PTR(rule); - } else if (r == 0) { + } else if (r < 0) + return r; + else if (r == 0) { /* Take over a foreign rule. */ r = set_ensure_put(&m->rules, &routing_policy_rule_hash_ops, existing); if (r < 0) @@ -346,11 +348,7 @@ static int routing_policy_rule_add(Manager *m, const RoutingPolicyRule *in, Rout assert(r > 0); set_remove(m->rules_foreign, existing); - } else if (r == 1) { - /* Already exists, do nothing. */ - ; - } else - return r; + } /* else r > 0: already exists, do nothing. */ if (ret) *ret = existing; From 59ca71a93d07cccd1a906f66047ffbf95e9cad99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 9 Jun 2021 12:40:35 +0200 Subject: [PATCH 2/4] networkd: drop one workaround initialization As for the other ones in src/network/, if they are removed, gcc warns when they are removed. Should fix Coverity CID#1457466. --- src/network/networkd-setlink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/network/networkd-setlink.c b/src/network/networkd-setlink.c index 4f25000338..478591b5bb 100644 --- a/src/network/networkd-setlink.c +++ b/src/network/networkd-setlink.c @@ -692,7 +692,7 @@ int link_request_to_set_master(Link *link) { } int link_request_to_set_mtu(Link *link, uint32_t mtu) { - Request *req = NULL; /* avoid false maybe-uninitialized warning */ + Request *req; const char *origin; uint32_t min_mtu; int r; From 21996f81b282569e2f9dd748b461fe853973eaeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 9 Jun 2021 12:36:06 +0200 Subject: [PATCH 3/4] test-capability: drop work-around initialization Since those workarounds have been added, work has been done to tighten up log_*() return values. Seems we get no warning with gcc-11.1.1-1.fc34.x86_64 and -O0/-O2. --- src/test/test-capability.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/test-capability.c b/src/test/test-capability.c index 7a781e57e4..94f15bfb21 100644 --- a/src/test/test-capability.c +++ b/src/test/test-capability.c @@ -248,7 +248,7 @@ static void test_ensure_cap_64bit(void) { } int main(int argc, char *argv[]) { - bool run_ambient = false; /* avoid false maybe-uninitialized warning */ + bool run_ambient; test_setup_logging(LOG_INFO); From 67e9c83bad583ef73a9d546e6abe4d67d28f88cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 9 Jun 2021 12:40:53 +0200 Subject: [PATCH 4/4] cryptsetup: remove unitialized workaround Doesn't seem needed anymore. --- src/cryptsetup/cryptsetup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c index 287069766c..89b8377ea6 100644 --- a/src/cryptsetup/cryptsetup.c +++ b/src/cryptsetup/cryptsetup.c @@ -1056,7 +1056,7 @@ static int attach_luks_or_plain_or_bitlk_by_tpm2( _cleanup_(sd_event_unrefp) sd_event *event = NULL; _cleanup_free_ char *friendly = NULL; int keyslot = arg_key_slot, r; - size_t decrypted_key_size = 0; /* avoid false maybe-uninitialized warning */ + size_t decrypted_key_size; assert(cd); assert(name);