public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: passt-dev@passt.top, Stefano Brivio <sbrivio@redhat.com>
Cc: David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH 2/4] conf: Remove overly cryptic selection of forward table
Date: Fri, 29 Sep 2023 15:50:20 +1000	[thread overview]
Message-ID: <20230929055022.48624-3-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20230929055022.48624-1-david@gibson.dropbear.id.au>

In a couple of places in conf(), we use a local 'fwd' variable to reference
one of our forwarding tables.  The value depends on which command line
option we're currently looking at, and is initialized rather cryptically
from an assignment side-effect within the if condition checking that
option.

Newer versions of cppcheck complain about this assignment being an always
true condition, but in any case it's both clearer and slightly shorter to
use separate if branches for the two cases and set the forwarding parameter
more directly.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
 conf.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/conf.c b/conf.c
index 551a9da..a235b31 100644
--- a/conf.c
+++ b/conf.c
@@ -1742,14 +1742,12 @@ void conf(struct ctx *c, int argc, char **argv)
 	/* Inbound port options can be parsed now (after IPv4/IPv6 settings) */
 	optind = 1;
 	do {
-		struct port_fwd *fwd;
-
 		name = getopt_long(argc, argv, optstring, options, NULL);
 
-		if ((name == 't' && (fwd = &c->tcp.fwd_in)) ||
-		    (name == 'u' && (fwd = &c->udp.fwd_in.f))) {
-			conf_ports(c, name, optarg, fwd);
-		}
+		if (name == 't')
+			conf_ports(c, name, optarg, &c->tcp.fwd_in);
+		else if (name == 'u')
+			conf_ports(c, name, optarg, &c->udp.fwd_in.f);
 	} while (name != -1);
 
 	if (c->mode == MODE_PASTA)
@@ -1777,14 +1775,12 @@ void conf(struct ctx *c, int argc, char **argv)
 	/* ...and outbound port options now that namespaces are set up. */
 	optind = 1;
 	do {
-		struct port_fwd *fwd;
-
 		name = getopt_long(argc, argv, optstring, options, NULL);
 
-		if ((name == 'T' && (fwd = &c->tcp.fwd_out)) ||
-		    (name == 'U' && (fwd = &c->udp.fwd_out.f))) {
-			conf_ports(c, name, optarg, fwd);
-		}
+		if (name == 'T')
+			conf_ports(c, name, optarg, &c->tcp.fwd_out);
+		else if (name == 'U')
+			conf_ports(c, name, optarg, &c->udp.fwd_out.f);
 	} while (name != -1);
 
 	if (!c->ifi4)
-- 
@@ -1742,14 +1742,12 @@ void conf(struct ctx *c, int argc, char **argv)
 	/* Inbound port options can be parsed now (after IPv4/IPv6 settings) */
 	optind = 1;
 	do {
-		struct port_fwd *fwd;
-
 		name = getopt_long(argc, argv, optstring, options, NULL);
 
-		if ((name == 't' && (fwd = &c->tcp.fwd_in)) ||
-		    (name == 'u' && (fwd = &c->udp.fwd_in.f))) {
-			conf_ports(c, name, optarg, fwd);
-		}
+		if (name == 't')
+			conf_ports(c, name, optarg, &c->tcp.fwd_in);
+		else if (name == 'u')
+			conf_ports(c, name, optarg, &c->udp.fwd_in.f);
 	} while (name != -1);
 
 	if (c->mode == MODE_PASTA)
@@ -1777,14 +1775,12 @@ void conf(struct ctx *c, int argc, char **argv)
 	/* ...and outbound port options now that namespaces are set up. */
 	optind = 1;
 	do {
-		struct port_fwd *fwd;
-
 		name = getopt_long(argc, argv, optstring, options, NULL);
 
-		if ((name == 'T' && (fwd = &c->tcp.fwd_out)) ||
-		    (name == 'U' && (fwd = &c->udp.fwd_out.f))) {
-			conf_ports(c, name, optarg, fwd);
-		}
+		if (name == 'T')
+			conf_ports(c, name, optarg, &c->tcp.fwd_out);
+		else if (name == 'U')
+			conf_ports(c, name, optarg, &c->udp.fwd_out.f);
 	} while (name != -1);
 
 	if (!c->ifi4)
-- 
2.41.0


  parent reply	other threads:[~2023-09-29  5:50 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-29  5:50 [PATCH 0/4] RFC: Updates for cppcheck-2.12 warnings David Gibson
2023-09-29  5:50 ` [PATCH 1/4] cppcheck: Make many pointers const David Gibson
2023-09-29  5:50 ` David Gibson [this message]
2023-09-29  5:50 ` [PATCH 3/4] cppcheck: Use "exhaustive" level checking when available David Gibson
2023-09-29  5:50 ` [PATCH 4/4] cppcheck: Work around bug in cppcheck 2.12.0 David Gibson
2023-09-29  5:52 ` [PATCH 0/4] RFC: Updates for cppcheck-2.12 warnings David Gibson
2023-09-29 15:31 ` Stefano Brivio
2023-10-03  2:36   ` David Gibson
2023-10-05  6:19     ` Stefano Brivio

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230929055022.48624-3-david@gibson.dropbear.id.au \
    --to=david@gibson.dropbear.id.au \
    --cc=passt-dev@passt.top \
    --cc=sbrivio@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).