Hi Paul,

> > -  if (nfd < 0)
> > +  if (nfd > TYPE_MAXIMUM (nfds_t) / 2)
> 
> This doesn't look right. What does TYPE_MAXIMUM (nfds_t) / 2 have to do with 
> anything?

TYPE_MAXIMUM (nfds_t) / 2 is good for a quick check against an out-of-bounds 
nfd.
POSIX [1] says that nfd is out-of-bounds if it is > getdtablesize().

> Plus, five lines later there's a comment that starts "Don't check 
> directly for NFD too large" and this seems to directly contradict the code 
> now.

This comment means that the code is a bit sloppy for nfd > getdtablesize().
IMO, this is OK for nfd < TYPE_MAXIMUM (nfds_t) / 2 because such values rarely
occur by accident. Whereas it's easy to pass -1 by mistake, which gets converted
to (nfds_t)-1.

> Plus, there's another "nfd < 0" in the WINDOWS_NATIVE case.

Oops. Thanks. I've corrected it now.

> How about the attached patch?

I disagree. It no longer catches the case nfd = (nfds_t)-1 quickly.

Bruno

[1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/poll.html


Reply via email to