[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
poll: enable argument check
From: |
Bruno Haible |
Subject: |
poll: enable argument check |
Date: |
Sat, 22 Apr 2017 14:59:52 +0200 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-72-generic; KDE/5.18.0; x86_64; ; ) |
On Mac OS X, I'm seeing this warning:
poll.c:338:11: warning: comparison of unsigned expression < 0 is always false
[-Wtautological-compare]
if (nfd < 0)
~~~ ^ ~
Indeed, nfd is of type nfds_t, which is an unsigned integer type per POSIX [1].
This fixes it:
2017-04-22 Bruno Haible <address@hidden>
poll: Enable argument check.
* lib/poll.c: Include intprops.h.
(poll): Check value of nfd correctly.
* modules/poll (Depends-on): Add intprops.
diff --git a/lib/poll.c b/lib/poll.c
index 88d9292..803ac0e 100644
--- a/lib/poll.c
+++ b/lib/poll.c
@@ -60,6 +60,7 @@
#include <time.h>
#include "assure.h"
+#include "intprops.h"
#ifndef INFTIM
# define INFTIM (-1)
@@ -335,7 +336,7 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout)
int maxfd, rc;
nfds_t i;
- if (nfd < 0)
+ if (nfd > TYPE_MAXIMUM (nfds_t) / 2)
{
errno = EINVAL;
return -1;
diff --git a/modules/poll b/modules/poll
index 57f0631..a7d117f 100644
--- a/modules/poll
+++ b/modules/poll
@@ -9,6 +9,7 @@ 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]
[1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/poll.h.html
- poll: enable argument check,
Bruno Haible <=