From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by passt.top (Postfix, from userid 1000) id 34F1F5A0269; Wed, 04 Mar 2026 17:32:32 +0100 (CET) From: Stefano Brivio To: passt-dev@passt.top Subject: [PATCH] tcp: Avoid comparison of expressions with different signedness in RTT_SET() Date: Wed, 4 Mar 2026 17:32:32 +0100 Message-ID: <20260304163232.2440892-1-sbrivio@redhat.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: ISWITMZDMLQCMZQGWM4QHV7YDROMVOF3 X-Message-ID-Hash: ISWITMZDMLQCMZQGWM4QHV7YDROMVOF3 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 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: With gcc 14.2, building against musl 1.2.5 (slightly outdated Alpine on x86_64): tcp.c: In function 'tcp_update_seqack_wnd': util.h:40:39: warning: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Wsign-compare] 40 | #define MIN(x, y) (((x) < (y)) ? (x) : (y)) | ^ tcp_conn.h:63:26: note: in expansion of macro 'MIN' 63 | (conn->rtt_exp = MIN(RTT_EXP_MAX, ilog2(MAX(1, rtt / RTT_STORE_MIN)))) | ^~~ tcp.c:1234:17: note: in expansion of macro 'RTT_SET' 1234 | RTT_SET(conn, tinfo->tcpi_rtt); | ^~~~~~~ util.h:40:54: warning: operand of '?:' changes signedness from 'int' to 'unsigned int' due to unsignedness of other operand [-Wsign-compare] 40 | #define MIN(x, y) (((x) < (y)) ? (x) : (y)) | ^~~ tcp_conn.h:63:26: note: in expansion of macro 'MIN' 63 | (conn->rtt_exp = MIN(RTT_EXP_MAX, ilog2(MAX(1, rtt / RTT_STORE_MIN)))) | ^~~ tcp.c:1234:17: note: in expansion of macro 'RTT_SET' 1234 | RTT_SET(conn, tinfo->tcpi_rtt); | ^~~~~~~ for some reason, that's not reported by gcc with glibc. Cast the result of ilog2() to unsigned before using it, as it's always positive the way we're using it. Should this ever break this for whatever unlikely reason, RTT_EXP_MAX is the fallback value we want to use anyway. Fixes: 000601ba86da ("tcp: Adaptive interval based on RTT for socket-side acknowledgement checks") Signed-off-by: Stefano Brivio --- tcp_conn.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tcp_conn.h b/tcp_conn.h index b7b85c1..6418ac4 100644 --- a/tcp_conn.h +++ b/tcp_conn.h @@ -60,7 +60,8 @@ struct tcp_tap_conn { #define RTT_STORE_MIN 100 /* us, minimum representable */ #define RTT_STORE_MAX ((long)(RTT_STORE_MIN << RTT_EXP_MAX)) #define RTT_SET(conn, rtt) \ - (conn->rtt_exp = MIN(RTT_EXP_MAX, ilog2(MAX(1, rtt / RTT_STORE_MIN)))) + (conn->rtt_exp = MIN(RTT_EXP_MAX, \ + (unsigned)ilog2(MAX(1, rtt / RTT_STORE_MIN)))) #define RTT_GET(conn) (RTT_STORE_MIN << conn->rtt_exp) bool tap_inactive :1; -- 2.43.0