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
---
tcp.c | 3 +--
tcp_internal.h | 4 ++--
2 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/tcp.c b/tcp.c
index edcabe27..10d9d0d5 100644
--- a/tcp.c
+++ b/tcp.c
@@ -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 40472c99..c623569c 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 - \
--
2.54.0