]> Savannah Git Hosting - gnulib.git/commitdiff
poll: improve fast check for out-of-range NFD
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 23 Apr 2017 01:48:39 +0000 (18:48 -0700)
committerBruno Haible <bruno@clisp.org>
Sun, 23 Apr 2017 08:59:45 +0000 (10:59 +0200)
* lib/poll.c: Do not include intprops.h.
(poll): Compare NFD to INT_MAX, not to TYPE_MAXIMUM (nfds_t) / 2.
* modules/poll (Depends-on): Remove intprops.

ChangeLog
lib/poll.c
modules/poll

index ad436a76a7fa659cd0d78d5d6e93828a8667dda4..43dd8617849ae83f8bbb6b8a6ba8ac002d82b101 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2017-04-22  Paul Eggert  <eggert@cs.ucla.edu>
 
+       poll: improve fast check for out-of-range NFD
+       * lib/poll.c: Do not include intprops.h.
+       (poll): Compare NFD to INT_MAX, not to TYPE_MAXIMUM (nfds_t) / 2.
+        * modules/poll (Depends-on): Remove intprops.
+
        ftoastr: cite a newer paper
        * lib/ftoastr.c (FTOASTR): In comment, cite Andrysco et al. 2016
        instead of Loitsch 2010.
index 69b3672f75057ffaf9d1101fdd24eb79e772f5a2..078b1bab41511891fb775a7ad77d5ec37b594589 100644 (file)
@@ -60,7 +60,6 @@
 #include <time.h>
 
 #include "assure.h"
-#include "intprops.h"
 
 #ifndef INFTIM
 # define INFTIM (-1)
@@ -336,13 +335,13 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout)
   int maxfd, rc;
   nfds_t i;
 
-  if (nfd > TYPE_MAXIMUM (nfds_t) / 2)
+  if (nfd > INT_MAX)
     {
       errno = EINVAL;
       return -1;
     }
-  /* Don't check directly for NFD too large.  Any practical use of a
-     too-large NFD is caught by one of the other checks below, and
+  /* Don't check directly for NFD greater than OPEN_MAX.  Any practical use
+     of a too-large NFD is caught by one of the other checks below, and
      checking directly for getdtablesize is too much of a portability
      and/or performance and/or correctness hassle.  */
 
@@ -434,7 +433,7 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout)
   int rc = 0;
   nfds_t i;
 
-  if (nfd > TYPE_MAXIMUM (nfds_t) / 2 || timeout < -1)
+  if (nfd > INT_MAX || timeout < -1)
     {
       errno = EINVAL;
       return -1;
index a7d117f532fe608c90b53ac200320740b39b3551..57f0631e723fbd3ccc9791a5f04a84dbf39c3498 100644 (file)
@@ -9,7 +9,6 @@ Depends-on:
 poll-h
 alloca          [test $HAVE_POLL = 0 || test $REPLACE_POLL = 1]
 assure          [test $HAVE_POLL = 0 || test $REPLACE_POLL = 1]
-intprops        [test $HAVE_POLL = 0 || test $REPLACE_POLL = 1]
 select          [test $HAVE_POLL = 0 || test $REPLACE_POLL = 1]
 sockets         [test $HAVE_POLL = 0 || test $REPLACE_POLL = 1]
 sys_select      [test $HAVE_POLL = 0 || test $REPLACE_POLL = 1]