diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c index 22e6138d6d..66726a7828 100644 --- a/dlls/ws2_32/socket.c +++ b/dlls/ws2_32/socket.c @@ -3496,7 +3496,11 @@ static struct pollfd *fd_sets_to_poll( const WS_fd_set *readfds, const WS_fd_set if (writefds) count += writefds->fd_count; if (exceptfds) count += exceptfds->fd_count; *count_ptr = count; - if (!count) return NULL; + if (!count) + { + SetLastError(WSAEINVAL); + return NULL; + } if (!(fds = HeapAlloc( GetProcessHeap(), 0, count * sizeof(fds[0])))) { SetLastError( ERROR_NOT_ENOUGH_MEMORY ); @@ -3619,7 +3623,7 @@ int WINAPI WS_select(int nfds, WS_fd_set *ws_readfds, TRACE("read %p, write %p, excp %p timeout %p\n", ws_readfds, ws_writefds, ws_exceptfds, ws_timeout); - if (!(pollfds = fd_sets_to_poll( ws_readfds, ws_writefds, ws_exceptfds, &count )) && count) + if (!(pollfds = fd_sets_to_poll( ws_readfds, ws_writefds, ws_exceptfds, &count ))) return SOCKET_ERROR; if (ws_timeout) diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c index e0f9ccfa92..fd61e78a20 100644 --- a/dlls/ws2_32/tests/sock.c +++ b/dlls/ws2_32/tests/sock.c @@ -1943,6 +1943,17 @@ static void test_select(void) FD_ZERO(&readfds); FD_ZERO(&writefds); FD_ZERO(&exceptfds); + + SetLastError(0); + ret = select(maxfd+1, 0, 0, 0, &select_timeout); + ok ( (ret == SOCKET_ERROR), "expected SOCKET_ERROR, got %i\n", ret); + ok ( GetLastError() == WSAEINVAL, "expected WSAEINVAL, got %i\n", ret); + + SetLastError(0); + ret = select(maxfd+1, &readfds, &writefds, &exceptfds, &select_timeout); + ok ( (ret == SOCKET_ERROR), "expected SOCKET_ERROR, got %i\n", ret); + ok ( GetLastError() == WSAEINVAL, "expected WSAEINVAL, got %i\n", ret); + FD_SET(INVALID_SOCKET, &readfds); SetLastError(0); ret = select(maxfd+1, &readfds, &writefds, &exceptfds, &select_timeout);