[PATCH 5/6] Cygwin: Fix warnings about narrowing conversions of socket ioctls
Corinna Vinschen
corinna-cygwin@cygwin.com
Wed Aug 7 14:06:26 GMT 2024
On Aug 6 19:58, Jon Turney wrote:
> On 05/08/2024 11:22, Corinna Vinschen wrote:
> > On Aug 4 22:48, Jon Turney wrote:
> > > Fix gcc 12 warnings about narrowing conversions of socket ioctl constants
> > > when used as case labels, e.g:
> > > [...]
> > The only caller, fhandler_socket::ioctl, passes an unsigned int
> > value to get_ifconf. Given how the value is defined, it would be
> > more straightforward to convert get_ifconf to
> >
> > get_ifconf (struct ifconf *ifc, unsigned int what);
> >
> > wouldn't it?
>
> Yeah, I'm not sure why I didn't do that. I think I got confused about where
> this is used from.
>
> (These constants are long int though, for whatever reason, so it's not
This is really old stuff. The _IO definitions have been taken from BSD
in some year with a 19 in front and never changed again. The fact that
the sizeof() gets cast to long is probably a remnant from the past when
the stuff was supposed to be used on 16 bit machines, but the value was
supposed to be 32 bit.
Given that the values are not supposed to be ever bigger than 32 bit,
we should fix the definitions of _IOR/_IOW, dropping the (long) cast.
Compare with current FreeBSD, which does not cast at all.
I did a quick check that dropping the cast does not change the value
of any of the dependent definitions in Cygwin headers. That shouldn't
happen anyway, given sizeof() returns a size_t, i. e. 64 bit unsigned.
> immediately obvious that they all can be converted to unsigned int without
> loss, but it seems they can)
>
> Revised patch attached.
LGTM. I will additionally push a patch dropping the useless casts.
Thanks,
Corinna
More information about the Cygwin-patches
mailing list