[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 5/5] slirp: Fix signed/unsigned comparison and varia
From: |
Mark Pizzolato |
Subject: |
[Qemu-devel] [PATCH 5/5] slirp: Fix signed/unsigned comparison and variable truncation warnings |
Date: |
Wed, 21 Oct 2015 16:15:17 -0700 |
Some warnings affect potentially wrapping sequence numbers. Careful
analysis of intent and consequences is necessary.
- Variable type changes where appropriate
- Explicit casts where appropriate
Signed-off-by: Mark Pizzolato <address@hidden>
---
slirp/bootp.c | 2 +-
slirp/dnssearch.c | 6 +++---
slirp/sbuf.c | 6 +++---
slirp/slirp.c | 2 +-
slirp/socket.c | 4 ++--
slirp/socket.h | 2 +-
slirp/tcp.h | 2 +-
slirp/tcp_input.c | 4 ++--
slirp/tcp_output.c | 12 ++++++------
9 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/slirp/bootp.c b/slirp/bootp.c
index 27a4032..79a5c80 100644
--- a/slirp/bootp.c
+++ b/slirp/bootp.c
@@ -284,7 +284,7 @@ static void bootp_reply(Slirp *slirp, const struct bootp_t
*bp)
if (slirp->vdnssearch) {
size_t spaceleft = sizeof(rbp->bp_vend) - (q - rbp->bp_vend);
val = slirp->vdnssearch_len;
- if (val + 1 > spaceleft) {
+ if ((size_t)val + 1 > spaceleft) {
g_warning("DHCP packet size exceeded, "
"omitting domain-search option.");
} else {
diff --git a/slirp/dnssearch.c b/slirp/dnssearch.c
index 4c9064e..dfe38be 100644
--- a/slirp/dnssearch.c
+++ b/slirp/dnssearch.c
@@ -135,7 +135,7 @@ static void domain_mklabels(CompactDomain *cd, const char
*input)
if ((len == 0 && cur_chr == '.') || len >= 64) {
goto fail;
}
- *len_marker = len;
+ *len_marker = (uint8_t)len;
output++;
len_marker = output;
@@ -222,7 +222,7 @@ static size_t domain_compactify(CompactDomain *domains,
size_t n)
if (moff < 0x3FFFu) {
cd->len -= cd->common_octets - 2;
cd->labels[cd->len - 1] = moff & 0xFFu;
- cd->labels[cd->len - 2] = 0xC0u | (moff >> 8);
+ cd->labels[cd->len - 2] = (uint8_t)(0xC0u | (moff >> 8));
}
}
@@ -301,7 +301,7 @@ int translate_dnssearch(Slirp *s, const char **names)
size_t len = bsrc_end - bsrc_start;
memmove(result + bdst_start, result + bsrc_start, len);
result[bdst_start - 2] = RFC3397_OPT_DOMAIN_SEARCH;
- result[bdst_start - 1] = len;
+ result[bdst_start - 1] = (uint8_t)len;
bsrc_end = bsrc_start;
bsrc_start -= MAX_OPT_LEN;
bdst_start -= MAX_OPT_LEN + OPT_HEADER_LEN;
diff --git a/slirp/sbuf.c b/slirp/sbuf.c
index 08ec2b4..b14f7d6 100644
--- a/slirp/sbuf.c
+++ b/slirp/sbuf.c
@@ -19,13 +19,13 @@ sbfree(struct sbuf *sb)
void
sbdrop(struct sbuf *sb, int num)
{
- int limit = sb->sb_datalen / 2;
+ u_int limit = sb->sb_datalen / 2;
/*
* We can only drop how much we have
* This should never succeed
*/
- if(num > sb->sb_cc)
+ if((u_int)num > sb->sb_cc)
num = sb->sb_cc;
sb->sb_cc -= num;
sb->sb_rptr += num;
@@ -173,7 +173,7 @@ sbcopy(struct sbuf *sb, int off, int len, char *to)
from -= sb->sb_datalen;
if (from < sb->sb_wptr) {
- if (len > sb->sb_cc) len = sb->sb_cc;
+ if ((u_int)len > sb->sb_cc) len = sb->sb_cc;
memcpy(to,from,len);
} else {
/* re-use off */
diff --git a/slirp/slirp.c b/slirp/slirp.c
index 05bb7e0..c597eb9 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -464,7 +464,7 @@ void slirp_pollfds_poll(GArray *pollfds, int select_error)
return;
}
- curtime = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
+ curtime = (u_int)qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
QTAILQ_FOREACH(slirp, &slirp_instances, entry) {
/*
diff --git a/slirp/socket.c b/slirp/socket.c
index 92c9bac..62cb6de 100644
--- a/slirp/socket.c
+++ b/slirp/socket.c
@@ -208,7 +208,7 @@ soread(struct socket *so)
return nn;
}
-int soreadbuf(struct socket *so, const char *buf, int size)
+int soreadbuf(struct socket *so, const char *buf, size_t size)
{
int n, nn, copy = size;
struct sbuf *sb = &so->so_snd;
@@ -468,7 +468,7 @@ sorecvfrom(struct socket *so)
udp_detach(so);
} else { /* A "normal" UDP packet */
struct mbuf *m;
- int len;
+ u_int len;
#ifdef _WIN32
unsigned long n;
#else
diff --git a/slirp/socket.h b/slirp/socket.h
index 57e0407..822b044 100644
--- a/slirp/socket.h
+++ b/slirp/socket.h
@@ -92,6 +92,6 @@ void soisfconnected(register struct socket *);
void sofwdrain(struct socket *);
struct iovec; /* For win32 */
size_t sopreprbuf(struct socket *so, struct iovec *iov, int *np);
-int soreadbuf(struct socket *so, const char *buf, int size);
+int soreadbuf(struct socket *so, const char *buf, size_t size);
#endif /* _SOCKET_H_ */
diff --git a/slirp/tcp.h b/slirp/tcp.h
index 2e2b403..4c791e1 100644
--- a/slirp/tcp.h
+++ b/slirp/tcp.h
@@ -108,7 +108,7 @@ struct tcphdr {
#define TCP_MSS 1460
#undef TCP_MAXWIN
-#define TCP_MAXWIN 65535 /* largest value for (unscaled) window
*/
+#define TCP_MAXWIN 65535u /* largest value for (unscaled) window
*/
#undef TCP_MAX_WINSHIFT
#define TCP_MAX_WINSHIFT 14 /* maximum window shift */
diff --git a/slirp/tcp_input.c b/slirp/tcp_input.c
index 011e48f..485dc38 100644
--- a/slirp/tcp_input.c
+++ b/slirp/tcp_input.c
@@ -1030,7 +1030,7 @@ trimthenstep6:
incr = incr * incr / cw;
tp->snd_cwnd = min(cw + incr, TCP_MAXWIN<<tp->snd_scale);
}
- if (acked > so->so_snd.sb_cc) {
+ if (acked > (int)so->so_snd.sb_cc) {
tp->snd_wnd -= so->so_snd.sb_cc;
sbdrop(&so->so_snd, (int )so->so_snd.sb_cc);
ourfinisacked = 1;
@@ -1468,7 +1468,7 @@ int
tcp_mss(struct tcpcb *tp, u_int offer)
{
struct socket *so = tp->t_socket;
- int mss;
+ u_int mss;
DEBUG_CALL("tcp_mss");
DEBUG_ARG("tp = %lx", (long)tp);
diff --git a/slirp/tcp_output.c b/slirp/tcp_output.c
index 74cc682..415b4b9 100644
--- a/slirp/tcp_output.c
+++ b/slirp/tcp_output.c
@@ -115,7 +115,7 @@ again:
* to send then the probe will be the FIN
* itself.
*/
- if (off < so->so_snd.sb_cc)
+ if (off < (int)so->so_snd.sb_cc)
flags &= ~TH_FIN;
win = 1;
} else {
@@ -124,7 +124,7 @@ again:
}
}
- len = min(so->so_snd.sb_cc, win) - off;
+ len = min((long)so->so_snd.sb_cc, win) - off;
if (len < 0) {
/*
@@ -166,12 +166,12 @@ again:
if (len) {
if (len == tp->t_maxseg)
goto send;
- if ((1 || idle || tp->t_flags & TF_NODELAY) &&
- len + off >= so->so_snd.sb_cc)
+ if ((1 || idle || (tp->t_flags & TF_NODELAY)) &&
+ ((len + off) >= (long)so->so_snd.sb_cc))
goto send;
if (tp->t_force)
goto send;
- if (len >= tp->max_sndwnd / 2 && tp->max_sndwnd > 0)
+ if ((len >= (long)(tp->max_sndwnd / 2)) && (tp->max_sndwnd > 0))
goto send;
if (SEQ_LT(tp->snd_nxt, tp->snd_max))
goto send;
@@ -280,7 +280,7 @@ send:
* Adjust data length if insertion of options will
* bump the packet length beyond the t_maxseg length.
*/
- if (len > tp->t_maxseg - optlen) {
+ if (len > (long)(tp->t_maxseg - optlen)) {
len = tp->t_maxseg - optlen;
sendalot = 1;
}
--
1.9.5.msysgit.0
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Qemu-devel] [PATCH 5/5] slirp: Fix signed/unsigned comparison and variable truncation warnings,
Mark Pizzolato <=