From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/12598 Path: news.gmane.org!.POSTED!not-for-mail From: Martin Galvan Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH] select.h: Make FD_{SET,CLR,ISSET} cast their fd argument to unsigned int Date: Wed, 14 Mar 2018 19:42:35 -0300 Message-ID: <20180314224235.5018-1-omgalvan.86@gmail.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1521067265 5154 195.159.176.226 (14 Mar 2018 22:41:05 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 14 Mar 2018 22:41:05 +0000 (UTC) Cc: Martin Galvan To: musl@lists.openwall.com Original-X-From: musl-return-12612-gllmg-musl=m.gmane.org@lists.openwall.com Wed Mar 14 23:41:01 2018 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1ewF4v-0001F0-LF for gllmg-musl@m.gmane.org; Wed, 14 Mar 2018 23:41:01 +0100 Original-Received: (qmail 13748 invoked by uid 550); 14 Mar 2018 22:43:05 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 13708 invoked from network); 14 Mar 2018 22:43:04 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=QWPNoFgPHWiN5o9wUhlRYqrgZfKUkTBbVt48DOc0IvY=; b=LpjVuH4gw1ouoGzexaCM6Tc1Y3oJJ7/+aaNsouVNyuIZsZbEkwys5Ib2kx3hMhyXYk 6adjb+U3Vei58Axl8mt9lIWRWf059Aj3UI0wVadY2e3KMgtb5+oBu85lHMUeqVbQEJ+w cyOxcyr8zt/XkYP89/jpDSkUwu2C+ubepBWnYHG4mmKNEFQYBXU8vSdo6on8SaRg+gTV LNKybZYqC4ocam/q4AQTTODiJDesHPlZwoYiFs3sVXBTa3+QueqjwD8aEQiVChVjQPqa +A8/szuwSuOVKC0Cc7VL/kZaRMt8yYT9xorIx8DTmUvqDKbQCw+tFmsJa4bnaG6g3ik1 2Ceg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=QWPNoFgPHWiN5o9wUhlRYqrgZfKUkTBbVt48DOc0IvY=; b=udXCRBrgv2x1MbJc5TfpBomxRl6dZhv9kojBYBA44mkyseRxFUWW9vugq54pAwSOGh NNuKrLM5hjl7S/Q7+WZQbP1JRQBWEFuGEoZBG8nQlPm+Efn3c4n/td4uLIrxafh17T0A H/M06CHAAflfJNHr1fd5q+ZGGVXmeIWMi3vd1heNqHOAIbm95/hNV/YTgYJA1qqf0jVt NBlS7FsldxSoUcjO7dbk4mLxHpiFF5JvSkQYrqvJ1zrT214dVwFexDCF/cia59GIjNVr +tfPvtkhTjd4NjDXf00V6Klj5pUSz69sEL4Tg4YqP3bljKtqpTpbbaQH8mCR6QpMPaJO kcAA== X-Gm-Message-State: AElRT7GL4TJG1dSmkENCh2g5rvwrIpFKv4hh41xLrLqs44KLUUuUxyOB sfRm0K9x4LdBOrcA2nri3q5zeQ== X-Google-Smtp-Source: AG47ELvuRpyNfKAzPgl/tZKDLuWJ9/IW3c7Nb9nSlN7ove1o8ZIn5Pb0to/LlYscqudSte45E4tzAA== X-Received: by 10.55.146.6 with SMTP id u6mr9540191qkd.327.1521067367378; Wed, 14 Mar 2018 15:42:47 -0700 (PDT) X-Mailer: git-send-email 2.16.2 Xref: news.gmane.org gmane.linux.lib.musl.general:12598 Archived-At: Currently, the FD_* macros assume their fd argument is always positive and perform operations on it that will result in signed-to-unsigned conversions. This will trigger gcc's -Wsign-conversion warning, which will break compilations if -Werror is active. This patch simply casts the fd to unsigned int. If the fd was indeed negative, things will break as they would have before. If it was postive, the warning will be squelched. No information should be lost on this cast either. There may be a more elegant solution to this, though, but this seems to be good enough IMHO. --- include/sys/select.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/include/sys/select.h b/include/sys/select.h index d34cbf10..604935e2 100644 --- a/include/sys/select.h +++ b/include/sys/select.h @@ -24,9 +24,12 @@ typedef struct { } fd_set; #define FD_ZERO(s) do { int __i; unsigned long *__b=(s)->fds_bits; for(__i=sizeof (fd_set)/sizeof (long); __i; __i--) *__b++=0; } while(0) -#define FD_SET(d, s) ((s)->fds_bits[(d)/(8*sizeof(long))] |= (1UL<<((d)%(8*sizeof(long))))) -#define FD_CLR(d, s) ((s)->fds_bits[(d)/(8*sizeof(long))] &= ~(1UL<<((d)%(8*sizeof(long))))) -#define FD_ISSET(d, s) !!((s)->fds_bits[(d)/(8*sizeof(long))] & (1UL<<((d)%(8*sizeof(long))))) +/* The casts to unsigned int are needed to avoid gcc's -Wsign-conversion warning. + Sign conversions shouldn't matter here because if the fd was negative there + was something wrong anyway, and there's not much we can do at this point. */ +#define FD_SET(d, s) ((s)->fds_bits[(unsigned int)(d)/(8*sizeof(long))] |= (1UL<<((unsigned int)(d)%(8*sizeof(long))))) +#define FD_CLR(d, s) ((s)->fds_bits[(unsigned int)(d)/(8*sizeof(long))] &= ~(1UL<<((unsigned int)(d)%(8*sizeof(long))))) +#define FD_ISSET(d, s) !!((s)->fds_bits[(unsigned int)(d)/(8*sizeof(long))] & (1UL<<((unsigned int)(d)%(8*sizeof(long))))) int select (int, fd_set *__restrict, fd_set *__restrict, fd_set *__restrict, struct timeval *__restrict); int pselect (int, fd_set *__restrict, fd_set *__restrict, fd_set *__restrict, const struct timespec *__restrict, const sigset_t *__restrict); -- 2.16.2