public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: Petr Skocik <pskocik@gmail.com>
Cc: cygwin@cygwin.com
Subject: Re: FD_{SET,ISSET,CLR} macros from sys/select.h triggerring gcc's -Wsign-conversion warnings
Date: Mon, 3 Aug 2020 12:45:52 +0200	[thread overview]
Message-ID: <20200803104552.GJ460314@calimero.vinschen.de> (raw)
In-Reply-To: <1f188b7e-6dc4-73af-e458-013760210469@gmail.com>

Hi Petr,

On Aug  2 20:08, Petr Skocik via Cygwin wrote:
> Example:
> 
> #include <sys/select.h>
> void f(int X)
> {
>     fd_set set;
>     FD_ZERO(&set);
>     FD_SET(X,&set);
>     FD_CLR(X+1,&set);
>     (void)FD_ISSET(X+2,&set);
> }
> 
> causes
> 
> fds.c:7:2: warning: conversion to ‘long unsigned int’ from ‘int’ may
> change the sign of the result [-Wsign-conversion]
>   FD_SET(X,&set);
>   ^~~~~~
> [...]
> on gcc with -Wconversion -Wsign-conversion.
> 
> The problem is caused by the following macros:
> 
>     #  define    NFDBITS    (sizeof (fd_mask) * 8)    /* bits per mask */
>     #  define    FD_SET(n, p)    ((p)->fds_bits[(n)/NFDBITS] |= (1L <<
> ((n) % NFDBITS)))
>     #  define    FD_CLR(n, p)    ((p)->fds_bits[(n)/NFDBITS] &= ~(1L <<
> ((n) % NFDBITS)))
>     #  define    FD_ISSET(n, p)    ((p)->fds_bits[(n)/NFDBITS] & (1L <<
> ((n) % NFDBITS)))
> 
> int-casting the sizeof and using 1UL instead of 1L fixes the problem:

Thanks.  I pushed a patch which will show up in the next Cygwin release:
https://sourceware.org/git/?p=newlib-cygwin.git;a=commitdiff;h=5717262b8ecf

Funny enough, while the GLibc version of sys/select.h does not generate
these warnings, the same problem still exists in the upstream FreeBSD
code.

For testing I uploaded a new developer snapshot to
https://cygwin.com/snapshots/  You only need to fetch the new
sys/select.h file.


Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer

  reply	other threads:[~2020-08-03 10:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-02 18:08 Petr Skocik
2020-08-03 10:45 ` Corinna Vinschen [this message]
2020-08-03 13:27   ` Petr Skocik
2020-08-03 14:29     ` Corinna Vinschen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200803104552.GJ460314@calimero.vinschen.de \
    --to=corinna-cygwin@cygwin.com \
    --cc=cygwin@cygwin.com \
    --cc=pskocik@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).