[v3,18/19] examples/l3fwd: fix operator precedence bugs

Message ID 20250205162448.161161-19-stephen@networkplumber.org (mailing list archive)
State Accepted
Delegated to: Thomas Monjalon
Headers
Series minor fixes from PVS studio bug list |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Stephen Hemminger Feb. 5, 2025, 4:23 p.m. UTC
The expression:

  if ((socketid = rte_lcore_to_socket_id(lcore) != 0) &&

gets evaluated as sockeid = (rte_lcore_to_socket_id(lcore) != 0)
which is not what was intended. This is goes all the way back
to first release.

Link: https://pvs-studio.com/en/blog/posts/cpp/1183/
Fixes: af75078fece3 ("first public release")
Cc: stable@dpdk.org

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 examples/l3fwd-power/main.c | 4 ++--
 examples/l3fwd/main.c       | 5 +++--
 2 files changed, 5 insertions(+), 4 deletions(-)
  

Patch

diff --git a/examples/l3fwd-power/main.c b/examples/l3fwd-power/main.c
index d279e664b3..e27b8531b5 100644
--- a/examples/l3fwd-power/main.c
+++ b/examples/l3fwd-power/main.c
@@ -1412,8 +1412,8 @@  check_lcore_params(void)
 							"mask\n", lcore);
 			return -1;
 		}
-		if ((socketid = rte_lcore_to_socket_id(lcore) != 0) &&
-							(numa_on == 0)) {
+		socketid = rte_lcore_to_socket_id(lcore);
+		if (socketid != 0 && numa_on == 0) {
 			printf("warning: lcore %u is on socket %d with numa "
 						"off\n", lcore, socketid);
 		}
diff --git a/examples/l3fwd/main.c b/examples/l3fwd/main.c
index 994b7dd8e5..ae3b4f6439 100644
--- a/examples/l3fwd/main.c
+++ b/examples/l3fwd/main.c
@@ -311,8 +311,9 @@  check_lcore_params(void)
 			printf("error: lcore %u is not enabled in lcore mask\n", lcore);
 			return -1;
 		}
-		if ((socketid = rte_lcore_to_socket_id(lcore) != 0) &&
-			(numa_on == 0)) {
+
+		socketid = rte_lcore_to_socket_id(lcore);
+		if (socketid != 0 && numa_on == 0) {
 			printf("warning: lcore %u is on socket %d with numa off\n",
 				lcore, socketid);
 		}