]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: Use assert_se() instead of assert() in various places
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 23 Apr 2025 09:45:59 +0000 (11:45 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 23 Apr 2025 11:48:16 +0000 (13:48 +0200)
assert() is compiled away if NDEBUG is set which causes an unused
variable warning in various places when the next commit is applied
so let's use assert_se() to avoid these warnings.

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

index 04e7c26c348c4f6a9edc44b3f8f6a4c5de20def7..ec662acceef46cffea5c8009435543c64a838b6b 100644 (file)
@@ -49,9 +49,9 @@ int ndisc_router_solicit_parse(sd_radv *ra, sd_ndisc_router_solicit *rs) {
                                       "Too small to be a router solicit, ignoring.");
 
         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);
+        assert_se(a);
+        assert_se(a->nd_rs_type == ND_ROUTER_SOLICIT);
+        assert_se(a->nd_rs_code == 0);
 
         r = ndisc_parse_options(rs->packet, &rs->options);
         if (r < 0)
index c6eac67c0ab093d5caaedc2c5cc11340c34ef077..926843e868a61721bb0615a260404bd394b43dce 100644 (file)
@@ -2280,7 +2280,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(!error_or_denial);
+        assert_se(!error_or_denial);
 
         return 0;
 }
@@ -3841,7 +3841,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(!error_or_denial);
+        assert_se(!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 6c2ec26a697af21bb622f7e2dad72820111bd47c..e9b8d6cad4c1402f56dfcfa49baa7800573c5ae7 100644 (file)
@@ -4897,7 +4897,7 @@ static int tpm2_kdfe(
 
         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(end > info && (uintptr_t) end - (uintptr_t) info == info_len);
+        assert_se(end > info && (uintptr_t) end - (uintptr_t) info == info_len);
 
         _cleanup_free_ void *buf = NULL;
         r = kdf_ss_derive(
index cac6cc0f50b999c64d668a5336994e4c9955edd4..12b8a6d748152c52cedb696f344be1487b64dd23 100644 (file)
@@ -139,12 +139,12 @@ TEST(label_ops_post) {
         fd = RET_NERRNO(get_dir_fd("label_test_dir", 0755));
         text1 = "Add initial texts to file for testing label operations to file1\n";
 
-        assert(labelling_op(fd, text1, "file1.txt", 0644) == 0);
+        assert_se(labelling_op(fd, text1, "file1.txt", 0644) == 0);
         assert_se(label_ops_post(fd, "file1.txt", true) == 0);
         assert_se(strlen(text1) == (size_t)buf.st_size);
         text2 = "Add text2 data to file2\n";
 
-        assert(labelling_op(fd, text2, "file2.txt", 0644) == 0);
+        assert_se(labelling_op(fd, text2, "file2.txt", 0644) == 0);
         assert_se(label_ops_post(fd, "file2.txt", true) == 0);
         assert_se(strlen(text2) == (size_t)buf.st_size);
         assert_se(label_ops_post(fd, "file3.txt", true) == -ENOENT);
index a5616c81212f5ff70c7949d39bd9d06123b55e83..907a6c5c732a520abfa7ac6ec23c693ef01e8862 100644 (file)
@@ -300,19 +300,19 @@ TEST(pty_open_peer) {
         _cleanup_free_ char *pty_path = NULL;
 
         pty_fd = openpt_allocate(O_RDWR|O_NOCTTY|O_CLOEXEC|O_NONBLOCK, &pty_path);
-        assert(pty_fd >= 0);
-        assert(pty_path);
+        assert_se(pty_fd >= 0);
+        assert_se(pty_path);
 
         peer_fd = pty_open_peer(pty_fd, O_RDWR|O_NOCTTY|O_CLOEXEC);
-        assert(peer_fd >= 0);
+        assert_se(peer_fd >= 0);
 
         static const char x[] = { 'x', '\n' };
-        assert(write(pty_fd, x, sizeof(x)) == 2);
+        assert_se(write(pty_fd, x, sizeof(x)) == 2);
 
         char buf[3];
-        assert(read(peer_fd, &buf, sizeof(buf)) == sizeof(x));
-        assert(buf[0] == x[0]);
-        assert(buf[1] == x[1]);
+        assert_se(read(peer_fd, &buf, sizeof(buf)) == sizeof(x));
+        assert_se(buf[0] == x[0]);
+        assert_se(buf[1] == x[1]);
 }
 
 TEST(terminal_new_session) {