From 787ca0ceb4fc643a1d9d061431969ae7c6f12466 Mon Sep 17 00:00:00 2001 From: "randomizedcoder dave.seddon.ca@gmail.com" Date: Fri, 18 Sep 2026 10:28:11 -0700 Subject: [PATCH] fix(timer): make the wrap-around top-bit test shift unsigned homa_timer_check_rpc() decides whether to send NEED_ACK with a wrap-around-safe comparison that tests the top bit of an unsigned difference: (rpc->done_timer_ticks + homa->request_ack_ticks - 1 - homa->timer_ticks) & 1 << 31 `1 << 31` shifts a 1 into the sign bit of a signed int, which is undefined behavior in C (the result isn't representable in int). Because it's a constant expression the compiler folds it, so behavior happens to be correct on gcc/x86 today, but it's UB on paper and a portability trap; `-Wshift-overflow=2` flags it. Use `1U << 31` so the shift is well-defined unsigned; the surrounding operands are already unsigned (u32 dominates the expression), so the masked result is unchanged. Verified: `-Wshift-overflow=2` warns at homa_timer.c:37 before and is clean after; the timer unit suite stays green (10/10), including homa_timer_check_rpc__request_ack whose tick sequence still emits "xmit NEED_ACK". Co-Authored-By: Claude Opus 4.8 --- homa_timer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homa_timer.c b/homa_timer.c index dc22461e..c241e77a 100644 --- a/homa_timer.c +++ b/homa_timer.c @@ -34,7 +34,7 @@ void homa_timer_check_rpc(struct homa_rpc *rpc) } else { /* >= comparison that handles tick wrap-around. */ if ((rpc->done_timer_ticks + homa->request_ack_ticks - - 1 - homa->timer_ticks) & 1 << 31) { + - 1 - homa->timer_ticks) & 1U << 31) { struct homa_need_ack_hdr h; homa_rpc_unlock(rpc);