[PATCH 5/6] Cygwin: Fix warnings about narrowing conversions of socket ioctls

Corinna Vinschen corinna-cygwin@cygwin.com
Mon Aug 5 10:22:11 GMT 2024


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:
> 
> > ../../../../src/winsup/cygwin/net.cc: In function ‘int get_ifconf(ifconf*, int)’:
> > ../../../../src/winsup/cygwin/net.cc:1940:18: error: narrowing conversion of ‘2152756069’ from ‘long int’ to ‘int’ [-Wnarrowing]
> ---
>  winsup/cygwin/net.cc | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc
> index 08c584fe5..b76af2d19 100644
> --- a/winsup/cygwin/net.cc
> +++ b/winsup/cygwin/net.cc
> @@ -1935,7 +1935,7 @@ get_ifconf (struct ifconf *ifc, int what)
>  	{
>  	  ++cnt;
>  	  strcpy (ifr->ifr_name, ifp->ifa_name);
> -	  switch (what)
> +	  switch ((long int)what)
>  	    {
>  	    case SIOCGIFFLAGS:
>  	      ifr->ifr_flags = ifp->ifa_ifa.ifa_flags;
> -- 
> 2.45.1

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?


Thanks,
Corinna


More information about the Cygwin-patches mailing list