Module: wine Branch: master Commit: 6733c40d789744ec0ee6fa30f8e14816968a0887 URL: http://source.winehq.org/git/wine.git/?a=commit;h=6733c40d789744ec0ee6fa30f8...
Author: Dan Kegel dank@kegel.com Date: Mon Oct 18 10:42:16 2010 +0000
ws2_32: Null select() should fail with WSAEINVAL.
---
dlls/ws2_32/socket.c | 8 ++++++-- dlls/ws2_32/tests/sock.c | 11 +++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c index 22e6138..66726a7 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 e0f9ccf..fd61e78 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);