From 5332be60d3897c7b86d28cf7b9d61c5dc6847fd6 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Wed, 23 Apr 2025 11:45:59 +0200 Subject: [PATCH] tree-wide: Use assert_se() instead of assert() in various places 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 | 6 +++--- src/login/logind-dbus.c | 4 ++-- src/shared/tpm2-util.c | 2 +- src/test/test-label.c | 4 ++-- src/test/test-terminal-util.c | 14 +++++++------- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/libsystemd-network/sd-ndisc-router-solicit.c b/src/libsystemd-network/sd-ndisc-router-solicit.c index 04e7c26c34..ec662accee 100644 --- a/src/libsystemd-network/sd-ndisc-router-solicit.c +++ b/src/libsystemd-network/sd-ndisc-router-solicit.c @@ -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) diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index c6eac67c0a..926843e868 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -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) diff --git a/src/shared/tpm2-util.c b/src/shared/tpm2-util.c index 6c2ec26a69..e9b8d6cad4 100644 --- a/src/shared/tpm2-util.c +++ b/src/shared/tpm2-util.c @@ -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( diff --git a/src/test/test-label.c b/src/test/test-label.c index cac6cc0f50..12b8a6d748 100644 --- a/src/test/test-label.c +++ b/src/test/test-label.c @@ -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); diff --git a/src/test/test-terminal-util.c b/src/test/test-terminal-util.c index a5616c8121..907a6c5c73 100644 --- a/src/test/test-terminal-util.c +++ b/src/test/test-terminal-util.c @@ -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) {