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.
This commit is contained in:
Daan De Meyer
2025-04-23 13:48:16 +02:00
parent a843382d1e
commit 5332be60d3
5 changed files with 15 additions and 15 deletions
@@ -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)
+2 -2
View 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)
+1 -1
View 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(
+2 -2
View 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);
+7 -7
View 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) {