Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <cc54de84-f6f6-41d7-98bb-9dc346344a6f@brad-house.com>
Date: Fri, 2 Aug 2024 17:27:26 -0400
From: Brad House <brad@...d-house.com>
To: musl@...ts.openwall.com
Subject: [PATCH 1/1] IN6_IS_ADDR_LOOPBACK() and similar macros warn on
 -Wcast-qual

I'm the maintainer of c-ares (https://c-ares.org) and have been scanning 
the CI build logs for various systems to catch warnings, and on Alpine 
Linux (which obviously uses musl c) we get these warnings, specifically 
when using clang (but not oddly not on gcc):

/__w/c-ares/c-ares/src/lib/ares__sortaddrinfo.c:93:9: warning: cast from 
'const struct in6_addr *' to 'unsigned char *' drops const qualifier 
[-Wcast-qual]
    93 |     if (IN6_IS_ADDR_MULTICAST(&addr6->sin6_addr)) {
       |         ^
/usr/include/netinet/in.h:120:48: note: expanded from macro 
'IN6_IS_ADDR_MULTICAST'
   120 | #define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *) (a))[0] == 0xff)
       |                                                ^
/__w/c-ares/c-ares/src/lib/ares__sortaddrinfo.c:95:16: warning: cast 
from 'const struct in6_addr *' to 'unsigned int *' drops const qualifier 
[-Wcast-qual]
    95 |     } else if (IN6_IS_ADDR_LOOPBACK(&addr6->sin6_addr) ||
       |                ^
/usr/include/netinet/in.h:115:24: note: expanded from macro 
'IN6_IS_ADDR_LOOPBACK'
   115 |         (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 
0 && \
       |                        ^
/__w/c-ares/c-ares/src/lib/ares__sortaddrinfo.c:96:16: warning: cast 
from 'const struct in6_addr *' to 'unsigned char *' drops const 
qualifier [-Wcast-qual]
    96 | IN6_IS_ADDR_LINKLOCAL(&addr6->sin6_addr)) {
       |                ^
/usr/include/netinet/in.h:123:24: note: expanded from macro 
'IN6_IS_ADDR_LINKLOCAL'
   123 |         ((((uint8_t *) (a))[0]) == 0xfe && (((uint8_t *) 
(a))[1] & 0xc0) == 0x80)
       |                        ^
/__w/c-ares/c-ares/src/lib/ares__sortaddrinfo.c:141:16: warning: cast 
from 'const struct in6_addr *' to 'unsigned int *' drops const qualifier 
[-Wcast-qual]
   141 |     } else if (IN6_IS_ADDR_V4MAPPED(&addr6->sin6_addr)) {
       |                ^
/usr/include/netinet/in.h:129:24: note: expanded from macro 
'IN6_IS_ADDR_V4MAPPED'
   129 |         (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 
0 && \
       |                        ^
/__w/c-ares/c-ares/src/lib/ares__sortaddrinfo.c:149:16: warning: cast 
from 'const struct in6_addr *' to 'unsigned int *' drops const qualifier 
[-Wcast-qual]
   149 |     } else if (IN6_IS_ADDR_V4COMPAT(&addr6->sin6_addr)) {
       |                ^
/usr/include/netinet/in.h:134:24: note: expanded from macro 
'IN6_IS_ADDR_V4COMPAT'
   134 |         (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 
0 && \
       |                        ^
/__w/c-ares/c-ares/src/lib/ares__sortaddrinfo.c:151:16: warning: cast 
from 'const struct in6_addr *' to 'unsigned char *' drops const 
qualifier [-Wcast-qual]
   151 |     } else if (IN6_IS_ADDR_SITELOCAL(&addr6->sin6_addr)) {
       |                ^
/usr/include/netinet/in.h:126:24: note: expanded from macro 
'IN6_IS_ADDR_SITELOCAL'
   126 |         ((((uint8_t *) (a))[0]) == 0xfe && (((uint8_t *) 
(a))[1] & 0xc0) == 0xc0)
       |                        ^
/__w/c-ares/c-ares/src/lib/ares__sortaddrinfo.c:189:16: warning: cast 
from 'const struct in6_addr *' to 'unsigned int *' drops const qualifier 
[-Wcast-qual]
   189 |     } else if (IN6_IS_ADDR_V4COMPAT(&addr6->sin6_addr) ||
       |                ^
/usr/include/netinet/in.h:134:24: note: expanded from macro 
'IN6_IS_ADDR_V4COMPAT'
   134 |         (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 
0 && \
       |                        ^

Full build output: 
https://github.com/c-ares/c-ares/actions/runs/10219723015/job/28278549865

I've attached a patch that will silence this warning by always casting 
to the comparison to const, but otherwise not impact the behavior.

-Brad

View attachment "musl-netinet-warning-fix.patch" of type "text/plain" (3868 bytes)

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.