From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by passt.top (Postfix, from userid 1000) id 79B195A031A; Fri, 21 Jun 2024 17:53:23 +0200 (CEST) From: Stefano Brivio To: passt-dev@passt.top Subject: [PATCH 2/2] udp: Reduce scope of rport in udp_invert_portmap() Date: Fri, 21 Jun 2024 17:53:23 +0200 Message-ID: <20240621155323.1313483-3-sbrivio@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240621155323.1313483-1-sbrivio@redhat.com> References: <20240621155323.1313483-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: YEJFYQOYKQ2F2A6OR2ERPNIW2OS4XHSH X-Message-ID-Hash: YEJFYQOYKQ2F2A6OR2ERPNIW2OS4XHSH X-MailFrom: sbrivio@passt.top X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Laurent Jacquot , David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: cppcheck 2.14 warns that the scope of the rport variable could be reduced: do that, as reverted commit c80fa6a6bb44 ("udp: Make rport calculation more local") did, but keep the temporary variable of in_port_t type, otherwise the sum gets promoted to int. Reported-by: David Gibson Signed-off-by: Stefano Brivio --- udp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/udp.c b/udp.c index 8181900..a854323 100644 --- a/udp.c +++ b/udp.c @@ -279,10 +279,12 @@ static void udp_invert_portmap(struct udp_fwd_ports *fwd) "Forward and reverse delta arrays must have same size"); for (i = 0; i < ARRAY_SIZE(fwd->f.delta); i++) { in_port_t delta = fwd->f.delta[i]; - in_port_t rport = i + delta; - if (delta) + if (delta) { + in_port_t rport = i + delta; + fwd->rdelta[rport] = NUM_PORTS - delta; + } } } -- 2.43.0