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:35:07 +0000 (15:35 -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
tests/unit/test_fd_tracker.c

index 06ef377a3a181c1b7528df89b076340f789c0f70..08968c00abc5fda6499f533bfd7cd284dd79b028 100644 (file)
@@ -373,7 +373,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 7c818b94bd2fb6cee2749016f89fc902f4278cce..d1414491314eb2fac0012174fd0fb1704d0e559c 100644 (file)
@@ -387,8 +387,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.026011 seconds and 4 git commands to generate.