From 5c00dfc7ed9f8b16cd502f58faf30da7006d31ff Mon Sep 17 00:00:00 2001 From: Bert Gijsbers Date: Fri, 28 Jun 2024 18:05:59 +0200 Subject: [PATCH] Properly compute the first parameter to the select(2) system call. --- src/yapp.cc | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/yapp.cc b/src/yapp.cc index 57dd5e335..324e0b08f 100644 --- a/src/yapp.cc +++ b/src/yapp.cc @@ -240,20 +240,23 @@ int YApplication::mainLoop() { for (fExitLoop = fExitApp; (fExitApp | fExitLoop) == false; ) { bool didIdle = handleIdle(); - + int nfds = 0; fd_set read_fds; FD_ZERO(&read_fds); fd_set write_fds; FD_ZERO(&write_fds); for (YPollIterType iPoll = polls.iterator(); ++iPoll; ) { - PRECONDITION(iPoll->fd() >= 0); + const int fd = iPoll->fd(); + PRECONDITION(fd >= 0); if (iPoll->forRead()) { - FD_SET(iPoll->fd(), &read_fds); + FD_SET(fd, &read_fds); } if (iPoll->forWrite()) { - FD_SET(iPoll->fd(), &write_fds); + FD_SET(fd, &write_fds); } + if (nfds <= fd) + nfds = fd + 1; } timeval timeout = {0, 0L}; @@ -266,7 +269,7 @@ int YApplication::mainLoop() { #endif int rc; - rc = select(sizeof(fd_set) * 8, + rc = select(nfds, SELECT_TYPE_ARG234 &read_fds, SELECT_TYPE_ARG234 &write_fds, nullptr,