Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHs-p=gd2Ubk9FFhxajLpo=Qg_C4SbiD9PiYtc56T-ZFOYU9yQ@mail.gmail.com>
Date: Fri, 6 Jun 2025 01:34:53 +0100
From: Andy Caldwell <andy.m.caldwell@...glemail.com>
To: musl@...ts.openwall.com
Cc: Rich Felker <dalias@...c.org>, David Steele <david@...ackrest.org>, noloader@...il.com
Subject: Re: Sign conversion warning in FD_ISSET()

On Fri, Jun 6, 2025 at 1:29 AM Nick Wellnhofer <wellnhofer@...um.de> wrote:
>
> On Jun 6, 2025, at 02:23, Andy Caldwell <andy.m.caldwell@...glemail.com> wrote:
> >
> >>> There probably is some way to get it right with clever use of the
> >>> ternary operator but I haven't come up with anything in the first few
> >>> seconds thinking about it.
> >>>
> >>> Rich
> >
> > Yes, the ternary operator can be used to create a C89-compatible
> > version (this allows anything coercible to an `int` or an `unsigned`,
> > so it mostly only refuses pointers and structures).
> >
> > #define SOCKET_TO_UNSIGNED(s) ((unsigned)(1?(s):0))
>
> This doesn't work with pointers because 0 is a null pointer constant. But if you change the value to 1, it should work.
>
> Nick
>

Thanks Nick and Rich, you are both correct, I originally had it as
`0?1:(s)` then changed it (without re-testing) for the email, like a
fool.  However in re-testing I notice that this only triggers a
warning `-Wint-conversion` rather than an error when passed a pointer
in C89 mode (it gives an error when passed a structure in any mode).

Andy

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.