Received: from eggs.gnu.org ([208.118.235.92]:43752) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T8dM8-0002AT-0L for qemu-devel@nongnu.org; Mon, 03 Sep 2012 16:34:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T8dM6-0002xX-Su for qemu-devel@nongnu.org; Mon, 03 Sep 2012 16:34:47 -0400 Received: from v220110690675601.yourvserver.net ([78.47.199.172]:51835) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T8dM6-0002xR-MR for qemu-devel@nongnu.org; Mon, 03 Sep 2012 16:34:46 -0400 From: Stefan Weil Date: Mon, 3 Sep 2012 22:34:44 +0200 Message-Id: <1346704484-15110-1-git-send-email-sw@weilnetz.de> Subject: [Qemu-devel] [PATCH] slirp: Fix error reported by static code analysis and remove wrong type casts List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jan Kiszka Cc: Stefan Weil , qemu-devel@nongnu.org Report from smatch: slirp/tcp_subr.c:127 tcp_respond(17) error: we previously assumed 'tp' could be null (see line 124) Fix this by checking 'tp' before reading its elements. The type casts of pointers to long are not related to the smatch report but happened to be near that code. Those type casts are not allowed when sizeof(pointer) != sizeof(long). Signed-off-by: Stefan Weil --- Coding style was not fixed by the patch! slirp/tcp_subr.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c index 025b374..5f3214c 100644 --- a/slirp/tcp_subr.c +++ b/slirp/tcp_subr.c @@ -114,9 +114,9 @@ tcp_respond(struct tcpcb *tp, struct tcpiphdr *ti, struct mbuf *m, int win = 0; DEBUG_CALL("tcp_respond"); - DEBUG_ARG("tp = %lx", (long)tp); - DEBUG_ARG("ti = %lx", (long)ti); - DEBUG_ARG("m = %lx", (long)m); + DEBUG_ARG("tp = %p", tp); + DEBUG_ARG("ti = %p", ti); + DEBUG_ARG("m = %p", m); DEBUG_ARG("ack = %u", ack); DEBUG_ARG("seq = %u", seq); DEBUG_ARG("flags = %x", flags); @@ -124,7 +124,7 @@ tcp_respond(struct tcpcb *tp, struct tcpiphdr *ti, struct mbuf *m, if (tp) win = sbspace(&tp->t_socket->so_rcv); if (m == NULL) { - if ((m = m_get(tp->t_socket->slirp)) == NULL) + if (tp && (m = m_get(tp->t_socket->slirp)) == NULL) return; tlen = 0; m->m_data += IF_MAXLINKHDR; -- 1.7.10