diff options
| author | David Gibson <david@gibson.dropbear.id.au> | 2026-06-15 18:18:33 +1000 |
|---|---|---|
| committer | Stefano Brivio <sbrivio@redhat.com> | 2026-06-16 23:49:49 +0200 |
| commit | 900ea8b46b7e978f55d61c5bdf0bef0f011972e7 (patch) | |
| tree | ce31eb4316432ae989e188c746b346ab2355de5b | |
| parent | 19cd4bacb076a8dfcedeb637e3aa883b66662844 (diff) | |
| download | passt-900ea8b46b7e978f55d61c5bdf0bef0f011972e7.tar passt-900ea8b46b7e978f55d61c5bdf0bef0f011972e7.tar.gz passt-900ea8b46b7e978f55d61c5bdf0bef0f011972e7.tar.bz2 passt-900ea8b46b7e978f55d61c5bdf0bef0f011972e7.tar.lz passt-900ea8b46b7e978f55d61c5bdf0bef0f011972e7.tar.xz passt-900ea8b46b7e978f55d61c5bdf0bef0f011972e7.tar.zst passt-900ea8b46b7e978f55d61c5bdf0bef0f011972e7.zip | |
tcp: MAX_WINDOW should be unsigned
Currently MAX_WINDOW is defined as a (signed) int, since '1' is a signed
literal. This means that when it's used in the SEQ_*() macros, we're
making a signed / unsigned comparison. While I don't think it was
incorrect in practice, confirming that requires reasoning though arcane
C type promotion rules.
Since it's obviously a non-negative value, change the constant to unsigned.
Change BUF_DISCARD_SIZE for the same reason, and because they're linked
via DISCARD_IOV_NUM, which must also be non-negative. Change the types
of a few variables in tcp_prepare_iov() to match (otherwise we'd get some
compiler warnings).
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
| -rw-r--r-- | tcp.c | 3 | ||||
| -rw-r--r-- | tcp_internal.h | 4 |
2 files changed, 3 insertions, 4 deletions
@@ -4069,9 +4069,8 @@ int tcp_prepare_iov(struct msghdr *msg, struct iovec *iov, msg->msg_iov = iov + DISCARD_IOV_NUM; msg->msg_iovlen = payload_iov_cnt; } else { - int discard_cnt, discard_iov_rem; + unsigned discard_cnt, discard_iov_rem, i; struct iovec *iov_start; - int i; discard_cnt = DIV_ROUND_UP(already_sent, BUF_DISCARD_SIZE); if (discard_cnt > DISCARD_IOV_NUM) { diff --git a/tcp_internal.h b/tcp_internal.h index 40472c9..c623569 100644 --- a/tcp_internal.h +++ b/tcp_internal.h @@ -12,9 +12,9 @@ #include "util.h" #define MAX_WS 8 -#define MAX_WINDOW (1 << (16 + (MAX_WS))) +#define MAX_WINDOW (1U << (16 + (MAX_WS))) -#define BUF_DISCARD_SIZE (1 << 20) +#define BUF_DISCARD_SIZE (1U << 20) #define DISCARD_IOV_NUM DIV_ROUND_UP(MAX_WINDOW, BUF_DISCARD_SIZE) #define MSS4 ROUND_DOWN(IP_MAX_MTU - \ |
