From 083f0ea3506553302f29eb5e25d2213edd34fba5 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Tue, 27 Dec 2005 19:22:07 +0000 Subject: [PATCH] (lwpInitSelect): The code to query the system's limit on file descriptors was not portable. Simply use FD_SETSIZE instead. The lower of the two applies, so this wastes storage if the system's limit is significantly below FD_SETSIZE. Not an issue, as FD_SETSIZE is fairly small. (lwpSleepFd): Return if fd is too large. Returning isn't nice, but better than the buffer overruns in the old code. (lwpSelect): Member nfile unused, remove. --- src/lib/lwp/sel.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/lib/lwp/sel.c b/src/lib/lwp/sel.c index 17b7ceeb..2668ec9a 100644 --- a/src/lib/lwp/sel.c +++ b/src/lib/lwp/sel.c @@ -41,11 +41,6 @@ #include #include #include - -#ifdef hpux -#include -#endif - #include "lwp.h" #include "lwpint.h" @@ -54,7 +49,6 @@ struct lwpSelect { int maxfd; int nfds; - int nfile; fd_set readmask; fd_set writemask; struct lwpProc **wait; @@ -69,14 +63,9 @@ lwpInitSelect(struct lwpProc *proc) { LwpSelect.maxfd = 0; LwpSelect.nfds = 0; -#ifdef hpux - LwpSelect.nfile = _NFILE; -#else - LwpSelect.nfile = getdtablesize(); -#endif FD_ZERO(&LwpSelect.readmask); FD_ZERO(&LwpSelect.writemask); - LwpSelect.wait = calloc(LwpSelect.nfile, sizeof(char *)); + LwpSelect.wait = calloc(FD_SETSIZE, sizeof(struct lwpProc *)); LwpSelect.delayq.head = 0; LwpSelect.delayq.tail = 0; LwpSelect.proc = proc; @@ -87,6 +76,8 @@ lwpSleepFd(int fd, int mask) { lwpStatus(LwpCurrent, "sleeping on fd %d for %d", fd, mask); + if (CANT_HAPPEN(fd > FD_SETSIZE)) + return; if (LwpSelect.wait[fd] != 0) { lwpStatus(LwpCurrent, "multiple sleeps attempted on file descriptor %d", fd);