]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
various: do not use assert_se as a workaround in non-test code
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 29 Apr 2025 10:49:54 +0000 (12:49 +0200)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 29 Apr 2025 12:59:32 +0000 (21:59 +0900)
This partially reverts 5332be60d3897c7b86d28cf7b9d61c5dc6847fd6. I expect that
there is no practical difference, but it seems philosophically wrong to use
assert_se(), i.e. for the generation of the code in non-debug builds, just to
suppress a warning. We have _unused_ for that, use it.

I verified that we don't get warnings with clang and -DNDEBUG=1 with this patch.

src/libsystemd-network/sd-ndisc-router-solicit.c
src/login/logind-dbus.c
src/shared/tpm2-util.c

index ec662acceef46cffea5c8009435543c64a838b6b..742ec9a1d2a9988a72a993f7ecfab160285b1bf8 100644 (file)
@@ -48,10 +48,10 @@ int ndisc_router_solicit_parse(sd_radv *ra, sd_ndisc_router_solicit *rs) {
                 return log_radv_errno(ra, SYNTHETIC_ERRNO(EBADMSG),
                                       "Too small to be a router solicit, ignoring.");
 
-        const struct nd_router_solicit *a = (const struct nd_router_solicit*) rs->packet->raw_packet;
-        assert_se(a);
-        assert_se(a->nd_rs_type == ND_ROUTER_SOLICIT);
-        assert_se(a->nd_rs_code == 0);
+        _unused_ const struct nd_router_solicit *a = (const struct nd_router_solicit*) rs->packet->raw_packet;
+        assert(a);
+        assert(a->nd_rs_type == ND_ROUTER_SOLICIT);
+        assert(a->nd_rs_code == 0);
 
         r = ndisc_parse_options(rs->packet, &rs->options);
         if (r < 0)
index 926843e868a61721bb0615a260404bd394b43dce..51edb60d04702c10ee7ef8ea9c94fadad622ea0f 100644 (file)
@@ -2179,7 +2179,8 @@ static int verify_shutdown_creds(
                 sd_bus_error *error) {
 
         _cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL;
-        bool multiple_sessions, blocked, interactive, error_or_denial = false;
+        bool multiple_sessions, blocked, interactive;
+        _unused_ bool error_or_denial = false;
         Inhibitor *offending = NULL;
         uid_t uid;
         int r;
@@ -2280,7 +2281,7 @@ static int verify_shutdown_creds(
          * to catch. In any case, it also means that the payload guarded by
          * these polkit calls should never be executed, and hence we should
          * never reach this point. */
-        assert_se(!error_or_denial);
+        assert(!error_or_denial);
 
         return 0;
 }
@@ -3775,7 +3776,7 @@ static int method_inhibit(sd_bus_message *message, void *userdata, sd_bus_error
         InhibitMode mm;
         InhibitWhat w;
         uid_t uid;
-        bool error_or_denial = false;
+        _unused_ bool error_or_denial = false;
         int r;
 
         assert(message);
@@ -3841,7 +3842,7 @@ static int method_inhibit(sd_bus_message *message, void *userdata, sd_bus_error
          * to catch. In any case, it also means that the payload guarded by
          * these polkit calls should never be executed, and hence we should
          * never reach this point. */
-        assert_se(!error_or_denial);
+        assert(!error_or_denial);
 
         r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_EUID|SD_BUS_CREDS_PID|SD_BUS_CREDS_PIDFD, &creds);
         if (r < 0)
index c18604b4dc1a1801d4c372cdb26c3ca50454fd47..f14e9eeae486e1a80861ff6562daa705ed48c87c 100644 (file)
@@ -4723,9 +4723,10 @@ static int tpm2_kdfe(
         if (!info)
                 return log_oom_debug();
 
-        void *end = mempcpy(mempcpy(stpcpy(info, label) + 1, context_u, context_u_size), context_v, context_v_size);
+        _unused_ void *end = mempcpy(mempcpy(stpcpy(info, label) + 1, context_u, context_u_size),
+                                     context_v, context_v_size);
         /* assert we copied exactly the right amount that we allocated */
-        assert_se(end > info && (uintptr_t) end - (uintptr_t) info == info_len);
+        assert(end > info && (uintptr_t) end - (uintptr_t) info == info_len);
 
         _cleanup_free_ void *buf = NULL;
         r = kdf_ss_derive(