Mail Archives: djgpp/1999/12/09/20:12:27

Date: Fri, 10 Dec 1999 01:52:53 +0100 (MET)
From: Gisle Vanem <giva AT bryggen DOT bgnett DOT no>
To: djgpp AT Delorie DOT com
Subject: select() error
Message-ID: <>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com

I think there is a bug in ./src/libc/compat/time/select.c. The code
assumes that select() is always called with a bitset equal to the size 
of 'fd_set'. E.g.

  fd_set fd_read;
  FD_ZERO (&fd_read);
  int num = select (10, &fd_read, NULL, NULL, NULL);

But I've seen code that supports bitset of arbitrary size (infact
from 1 to unlimited size).  Here the size of 'read' bitset is just 
large enough to hold the 'fds' of interest.  Which normally is less
than 256 fds (bits). And with correct typecast of an IN/OUT parameter
this is no problem. 


    /* Exit if we found what we were waiting for.  */
    if (ready > 0)
      if (readfds)
        *readfds = oread;
This may overwrite users bitset in 'readfds'. Similarily for
'writefds' and 'exceptfds'.

Solution would be to loop and set or clear maximum 'nfds' bits.

Gisle V.

- Raw text -

  webmaster     delorie software   privacy  
  Copyright 2019   by DJ Delorie     Updated Jul 2019