From d35973833e6bf05fec29100a4d5e66bb07b06659 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Tue, 24 Apr 2018 16:39:35 -0700 Subject: fix a number of cppcheck complaints (not all) --- src/platform/posix/posix_epdesc.c | 11 +++++----- src/platform/posix/posix_pipedesc.c | 4 ++-- src/platform/posix/posix_udp.c | 41 ++++++++++++++++++++----------------- 3 files changed, 29 insertions(+), 27 deletions(-) (limited to 'src/platform/posix') diff --git a/src/platform/posix/posix_epdesc.c b/src/platform/posix/posix_epdesc.c index 196b206a..f97f12b8 100644 --- a/src/platform/posix/posix_epdesc.c +++ b/src/platform/posix/posix_epdesc.c @@ -129,9 +129,9 @@ static void nni_posix_epdesc_doaccept(nni_posix_epdesc *ed) { nni_aio *aio; - int newfd; while ((aio = nni_list_first(&ed->acceptq)) != NULL) { + int newfd; #ifdef NNG_USE_ACCEPT4 newfd = accept4(ed->node.fd, NULL, NULL, SOCK_CLOEXEC); @@ -195,9 +195,8 @@ nni_posix_epdesc_doerror(nni_posix_epdesc *ed) static void nni_posix_epdesc_doclose(nni_posix_epdesc *ed) { - nni_aio * aio; - struct sockaddr_un *sun; - int fd; + nni_aio *aio; + int fd; ed->closed = true; while ((aio = nni_list_first(&ed->acceptq)) != NULL) { @@ -210,10 +209,10 @@ nni_posix_epdesc_doclose(nni_posix_epdesc *ed) nni_posix_pollq_remove(&ed->node); if ((fd = ed->node.fd) != -1) { - ed->node.fd = -1; + struct sockaddr_un *sun = (void *) &ed->locaddr; + ed->node.fd = -1; (void) shutdown(fd, SHUT_RDWR); (void) close(fd); - sun = (void *) &ed->locaddr; if ((sun->sun_family == AF_UNIX) && (ed->loclen != 0)) { (void) unlink(sun->sun_path); } diff --git a/src/platform/posix/posix_pipedesc.c b/src/platform/posix/posix_pipedesc.c index 62531f9c..72251372 100644 --- a/src/platform/posix/posix_pipedesc.c +++ b/src/platform/posix/posix_pipedesc.c @@ -202,8 +202,7 @@ nni_posix_pipedesc_doread(nni_posix_pipedesc *pd) static void nni_posix_pipedesc_cb(void *arg) { - nni_posix_pipedesc *pd = arg; - int events = 0; + nni_posix_pipedesc *pd = arg; nni_mtx_lock(&pd->mtx); if (pd->node.revents & POLLIN) { @@ -215,6 +214,7 @@ nni_posix_pipedesc_cb(void *arg) if (pd->node.revents & (POLLHUP | POLLERR | POLLNVAL)) { nni_posix_pipedesc_doclose(pd); } else { + int events = 0; if (!nni_list_empty(&pd->writeq)) { events |= POLLOUT; } diff --git a/src/platform/posix/posix_udp.c b/src/platform/posix/posix_udp.c index b414fa95..37f79431 100644 --- a/src/platform/posix/posix_udp.c +++ b/src/platform/posix/posix_udp.c @@ -143,25 +143,28 @@ nni_posix_udp_dosend(nni_plat_udp *udp) } #endif - for (unsigned i = 0; i < niov; i++) { - iov[i].iov_base = aiov[i].iov_buf; - iov[i].iov_len = aiov[i].iov_len; - } - hdr.msg_iov = iov; - hdr.msg_iovlen = niov; - hdr.msg_name = &ss; - hdr.msg_namelen = len; - hdr.msg_flags = NNI_MSG_NOSIGNAL; - hdr.msg_control = NULL; - hdr.msg_controllen = 0; - - if ((cnt = sendmsg(udp->udp_fd, &hdr, 0)) < 0) { - if ((errno == EAGAIN) || - (errno == EWOULDBLOCK)) { - // Cannot send now, leave at head. - return; + if (rv == 0) { + for (unsigned i = 0; i < niov; i++) { + iov[i].iov_base = aiov[i].iov_buf; + iov[i].iov_len = aiov[i].iov_len; + } + hdr.msg_iov = iov; + hdr.msg_iovlen = niov; + hdr.msg_name = &ss; + hdr.msg_namelen = len; + hdr.msg_flags = NNI_MSG_NOSIGNAL; + hdr.msg_control = NULL; + hdr.msg_controllen = 0; + + if ((cnt = sendmsg(udp->udp_fd, &hdr, 0)) < + 0) { + if ((errno == EAGAIN) || + (errno == EWOULDBLOCK)) { + // Cannot send now, leave. + return; + } + rv = nni_plat_errno(errno); } - rv = nni_plat_errno(errno); } } @@ -176,7 +179,6 @@ nni_posix_udp_cb(void *arg) { nni_plat_udp *udp = arg; int revents; - int events = 0; nni_mtx_lock(&udp->udp_mtx); revents = udp->udp_pitem.revents; @@ -189,6 +191,7 @@ nni_posix_udp_cb(void *arg) if (revents & (POLLHUP | POLLERR | POLLNVAL)) { nni_posix_udp_doclose(udp); } else { + int events = 0; if (!nni_list_empty(&udp->udp_sendq)) { events |= POLLOUT; } -- cgit v1.2.3-70-g09d2