Re: [PATCH v2] Fix cast errors with clang

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 10/21/2014 08:22 AM, Roman Bogorodskiy wrote:
> Build with clang fails with:
> 
>   CC       util/libvirt_util_la-virsocketaddr.lo
> util/virsocketaddr.c:904:17: error: cast from 'struct sockaddr *' to
> 'struct sockaddr_in *' increases required alignment from 1 to 4
> [-Werror,-Wcast-align]
>         inet4 = (struct sockaddr_in*) res->ai_addr;
>                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> util/virsocketaddr.c:909:17: error: cast from 'struct sockaddr *' to
> 'struct sockaddr_in6 *' increases required alignment from 1 to 4
> [-Werror,-Wcast-align]
>         inet6 = (struct sockaddr_in6*) res->ai_addr;
>                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 2 errors generated.
> 
> Fix that by replacing virSocketAddrParseInternal() call with
> virSocketAddrParse() in the virSocketAddrIsNumericLocalhost() function.
> virSocketAddrParse stores an address in virSocketAddr.
> virSocketAddr uses a union to store an address, so it doesn't
> need casting.
> ---
>  src/util/virsocketaddr.c | 20 ++++++--------------
>  1 file changed, 6 insertions(+), 14 deletions(-)
> 

>      bool ret = false;

You could drop this...

>  
> -    if (virSocketAddrParseInternal(&res, addr, AF_UNSPEC, false) < 0)
> +    if (virSocketAddrParse(&res, addr, AF_UNSPEC) < 0)
>          return ret;

by making this 'return false'

>  
> -    switch (res->ai_addr->sa_family) {
> +    switch (res.data.stor.ss_family) {
>      case AF_INET:
> -        inet4 = (struct sockaddr_in*) res->ai_addr;
> -        ret = memcmp(&inet4->sin_addr.s_addr, &tmp.s_addr,
> -                     sizeof(inet4->sin_addr.s_addr)) == 0;
> -        break;
> +        return memcmp(&res.data.inet4.sin_addr.s_addr, &tmp.s_addr,
> +                     sizeof(res.data.inet4.sin_addr.s_addr)) == 0;
>      case AF_INET6:
> -        inet6 = (struct sockaddr_in6*) res->ai_addr;
> -        ret = IN6_IS_ADDR_LOOPBACK(&(inet6->sin6_addr));
> -        break;
> +        return IN6_IS_ADDR_LOOPBACK(&res.data.inet6.sin6_addr);
>      }
>  
> -    freeaddrinfo(res);
>      return ret;

and also this one. (ret is never assigned anything else in the
function).  Whether or not you make that additional cleanup,

ACK.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]