From: Francis Deslauriers Date: Thu, 19 Aug 2021 21:14:46 +0000 (-0400) Subject: Fix: statements with side-effects in assert statements X-Git-Tag: v2.12.6~11 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=e0ad3e31a29af205ab5b9d73d9866410c6d3ee03;p=lttng-tools.git Fix: statements with side-effects in assert statements 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 Signed-off-by: Jérémie Galarneau Change-Id: I0b11c8e25c3380563332b4c0fad15f70b09a7335 --- diff --git a/src/bin/lttng-sessiond/agent-thread.c b/src/bin/lttng-sessiond/agent-thread.c index 06ef377a3..08968c00a 100644 --- a/src/bin/lttng-sessiond/agent-thread.c +++ b/src/bin/lttng-sessiond/agent-thread.c @@ -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) { diff --git a/tests/unit/test_fd_tracker.c b/tests/unit/test_fd_tracker.c index 7c818b94b..d14144913 100644 --- a/tests/unit/test_fd_tracker.c +++ b/tests/unit/test_fd_tracker.c @@ -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);