Fix: statements with side-effects in assert statements
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Thu, 19 Aug 2021 21:14:46 +0000 (17:14 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 23 Sep 2021 19:29:51 +0000 (15:29 -0400)
Background
==========
When building with the NDEBUG definition the `assert()` statements are
removed.

Issue
=====
Currently, a few `assert()` statements in the code base contain
statements that have side effects and removing them changes the
behavior for the program.

Fix
===
Extract the statements with side effects out of the `assert()`
statements.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I0b11c8e25c3380563332b4c0fad15f70b09a7335

src/bin/lttng-sessiond/agent-thread.c
src/bin/lttng-sessiond/ust-app.c
tests/unit/test_fd_tracker.c

index e09796e329a173cafc0344a80af85d1564bc6ee4..2f0fd6f914e4f597f76dc0036cfe0c2ad1d8b8b4 100644 (file)
@@ -387,7 +387,8 @@ static void *thread_agent_management(void *data)
        if (reg_sock) {
                uint16_t port;
 
-               assert(lttcomm_sock_get_port(reg_sock, &port) == 0);
+               ret = lttcomm_sock_get_port(reg_sock, &port);
+               assert(ret == 0);
 
                ret = write_agent_port(port);
                if (ret) {
index c902b21768bb3c6dd2e4e059cc6e76b52be84bcd..ae2db857dd7835554c57f9683bae6ce5524a3445 100644 (file)
@@ -1249,6 +1249,7 @@ static struct ust_app_event_notifier_rule *alloc_ust_app_event_notifier_rule(
 {
        enum lttng_event_rule_generate_exclusions_status
                        generate_exclusion_status;
+       enum lttng_condition_status cond_status;
        struct ust_app_event_notifier_rule *ua_event_notifier_rule;
        struct lttng_condition *condition = NULL;
        const struct lttng_event_rule *event_rule = NULL;
@@ -1269,9 +1270,9 @@ static struct ust_app_event_notifier_rule *alloc_ust_app_event_notifier_rule(
        assert(lttng_condition_get_type(condition) ==
                        LTTNG_CONDITION_TYPE_EVENT_RULE_MATCHES);
 
-       assert(LTTNG_CONDITION_STATUS_OK ==
-                       lttng_condition_event_rule_matches_get_rule(
-                                       condition, &event_rule));
+       cond_status = lttng_condition_event_rule_matches_get_rule(
+                       condition, &event_rule);
+       assert(cond_status == LTTNG_CONDITION_STATUS_OK);
        assert(event_rule);
 
        ua_event_notifier_rule->error_counter_index =
index 29d50873b99219b81b56d3b10a55277c63eb25da..a1e4c017a710fe175f1df26e96b055ec3712d68b 100644 (file)
@@ -394,8 +394,10 @@ void test_unsuspendable_close_untracked(void)
 
        ret = pipe(unknown_fds);
        assert(!ret);
-       assert(close(unknown_fds[0]) == 0);
-       assert(close(unknown_fds[1]) == 0);
+       ret = close(unknown_fds[0]);
+       assert(ret == 0);
+       ret = close(unknown_fds[1]);
+       assert(ret == 0);
 
        ret = fd_tracker_open_unsuspendable_fd(tracker, &out_fd,
                        NULL, 1, noop_open, &stdout_fd);
This page took 0.030781 seconds and 5 git commands to generate.