]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUILD: http_fetch: address a few aliasing warnings with older compilers
authorWilly Tarreau <w@1wt.eu>
Sun, 9 May 2021 08:32:54 +0000 (10:32 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 9 May 2021 08:32:54 +0000 (10:32 +0200)
gcc-4.4 complains about aliasing in smp_fetch_url_port() and
smp_fetch_url_ip() because the local addr variable is casted to sturct
sockaddr_in before being checked. The family should be checked on the
sockaddr_storage and we have a function to retrieve the port.
The compiler still sees some warnings but these ones are OK now.

src/http_fetch.c

index 020b25fcf571a985d2287fb3cb697188c7ff1d0d..1f3fa4e0cd02edb644e82175991881727b87d670 100644 (file)
@@ -710,7 +710,7 @@ static int smp_fetch_url_ip(const struct arg *args, struct sample *smp, const ch
        sl = http_get_stline(htx);
        url2sa(HTX_SL_REQ_UPTR(sl), HTX_SL_REQ_ULEN(sl), &addr, NULL);
 
-       if (((struct sockaddr_in *)&addr)->sin_family != AF_INET)
+       if (addr.ss_family != AF_INET)
                return 0;
 
        smp->data.type = SMP_T_IPV4;
@@ -731,11 +731,11 @@ static int smp_fetch_url_port(const struct arg *args, struct sample *smp, const
        sl = http_get_stline(htx);
        url2sa(HTX_SL_REQ_UPTR(sl), HTX_SL_REQ_ULEN(sl), &addr, NULL);
 
-       if (((struct sockaddr_in *)&addr)->sin_family != AF_INET)
+       if (addr.ss_family != AF_INET)
                return 0;
 
        smp->data.type = SMP_T_SINT;
-       smp->data.u.sint = ntohs(((struct sockaddr_in *)&addr)->sin_port);
+       smp->data.u.sint = get_host_port(&addr);
        smp->flags = 0;
        return 1;
 }