From: Mihai Pogonaru Date: Wed, 26 Jun 2019 01:54:32 +0000 (+0300) Subject: Fix poll() ret variable type and select() maxfd calculation X-Git-Tag: RELEASE-0.4~54 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=9bf7cef3c04092be1facb6c638b13b97247eef4f;p=unikraft%2Flibs%2Flwip.git Fix poll() ret variable type and select() maxfd calculation Poll ret variable must be declared as int Select must calculate maxfd as the maximum between lwip file descriptors Signed-off-by: Mihai Pogonaru Reviewed-by: Costin Lupu --- diff --git a/sockets.c b/sockets.c index 77235e9..e95758d 100644 --- a/sockets.c +++ b/sockets.c @@ -335,7 +335,8 @@ EXIT: int poll(struct pollfd fds[], nfds_t nfds, int timeout) { - unsigned int i, ret; + int ret; + unsigned int i; struct sock_net_file *file; struct pollfd lwip_fds[nfds]; @@ -395,7 +396,6 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, maxfd = 0; for (i = 0; i < nfds; i++) { if (readfds && FD_ISSET(i, readfds)) { - maxfd = i; file = sock_net_file_get(i); if (PTRISERR(file)) { LWIP_DEBUGF(SOCKETS_DEBUG, @@ -405,11 +405,12 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, SOCK_NET_SET_ERRNO(PTR2ERR(file)); goto EXIT; } + if (maxfd < file->sock_fd) + maxfd = file->sock_fd; FD_SET(file->sock_fd, &rd); vfscore_put_file(&file->vfscore_file); /* release refcount */ } if (writefds && FD_ISSET(i, writefds)) { - maxfd = i; file = sock_net_file_get(i); if (PTRISERR(file)) { LWIP_DEBUGF(SOCKETS_DEBUG, @@ -419,11 +420,12 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, SOCK_NET_SET_ERRNO(PTR2ERR(file)); goto EXIT; } + if (maxfd < file->sock_fd) + maxfd = file->sock_fd; FD_SET(file->sock_fd, &wr); vfscore_put_file(&file->vfscore_file); /* release refcount */ } if (exceptfds && FD_ISSET(i, exceptfds)) { - maxfd = i; file = sock_net_file_get(i); if (PTRISERR(file)) { LWIP_DEBUGF(SOCKETS_DEBUG, @@ -433,6 +435,8 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, SOCK_NET_SET_ERRNO(PTR2ERR(file)); goto EXIT; } + if (maxfd < file->sock_fd) + maxfd = file->sock_fd; FD_SET(file->sock_fd, &xc); vfscore_put_file(&file->vfscore_file); /* release refcount */ }