From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: from second.openwall.net (second.openwall.net [193.110.157.125]) by inbox.vuxu.org (Postfix) with SMTP id 9588B27D01 for ; Sat, 3 Aug 2024 02:02:31 +0200 (CEST) Received: (qmail 21964 invoked by uid 550); 3 Aug 2024 00:02:26 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 21920 invoked from network); 3 Aug 2024 00:02:25 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brad-house.com; s=google; t=1722643337; x=1723248137; darn=lists.openwall.com; h=in-reply-to:from:content-language:references:cc:to:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=VCXeUHxzxnKEkRteZ2R+YF51IrnCjHJtsNi8Pwhr4Ns=; b=VZ7zn96oQAWUhkKWowXQ1ymnczhrxJ1t1cdS3ZU5OHK3b5A0//NiPrp3A1XodbAdzQ r5NofWwV+/aE1pF8Dap1NsPgFouKmnqROTjBytV8pvHgpDEFjBZs9QP0FZX2LoljNQIs taWxBTxq8BwhKAA7GCy3fdURpQmEXjYKPpMeFWaM1Y6eoEGAeOlVlDC31YENaFBsF/In 8/fJ9mL9od5PQDkgpKvmkaFV7wYQ98KPHD6uGQw8xlFtECfZiYaBrOa+x9sg5+MnyBUp FN9d/6NWhulPz+DYsHQUzEevx0HXA/oWeTPRr8xNS6PN9+H3sxGMSK1CAIQO9z0yI+V6 FXBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722643337; x=1723248137; h=in-reply-to:from:content-language:references:cc:to:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=VCXeUHxzxnKEkRteZ2R+YF51IrnCjHJtsNi8Pwhr4Ns=; b=CDnUVd497qstDADfuVjcBD9RoY9/rZ7Vi3LEqxdy8Ynz5Bd5mbdeCMq6284rAn/+ev iUWmqtuMOoOSJlJ3DlE5GuuEfT88jlBO7ZGoEgQPfIxIx+JzgtOKBuRAzvBmcWhuFAgW i7a3sbfUe1Hq+O9el9IRnUAtzTLjNxDkXP9BW7NiLmlu+Rrx5EbEeJkhUNrYXCyAajj6 lzAwCLgi/RxUzz4WL18buDXwKzjD8mrTnS6EPF9p9smQDv7+7g4JzzmHkm7hD+K88pOP AiKsN/ln6S3eUX7ljPuWAJ+thWY+T5/yVGvDLervv+SDh1kk4CjNXD2B+YAgeaKF6LPw WzxA== X-Gm-Message-State: AOJu0Yy4Y9O/2VpwP79QKD9EQYv8K3Go6wzk/RLgn7giMUjTUSyT0i9w vhhWPJ6gkJog6KOAKMNZz+cwck6DU+Sg0ZBailEzAKYuOGuWVZ4Of7JI+fbpFzxI0umA7zA2Gom x X-Google-Smtp-Source: AGHT+IFyfoSzz/kRfR9ngeUxOL0Fvm5gVvDyCgmIHRXPuF6cTNl9Nody/oYXZiEh6EzwXLM7Hl8+3A== X-Received: by 2002:a0d:fc05:0:b0:630:f6b0:6c3d with SMTP id 00721157ae682-68961416ae6mr57336667b3.23.1722643337232; Fri, 02 Aug 2024 17:02:17 -0700 (PDT) Content-Type: multipart/mixed; boundary="------------tVz02ZdaBDbm5Uthz2XJpxrm" Message-ID: <4c03697d-36fd-42e3-8a27-e121d3acc522@brad-house.com> Date: Fri, 2 Aug 2024 20:02:16 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: musl@lists.openwall.com Cc: Rich Felker References: <20240802233801.GU10433@brightrain.aerifal.cx> Content-Language: en-US From: Brad House In-Reply-To: <20240802233801.GU10433@brightrain.aerifal.cx> Subject: Re: [musl] [PATCH 1/1] IN6_IS_ADDR_LOOPBACK() and similar macros warn on -Wcast-qual This is a multi-part message in MIME format. --------------tVz02ZdaBDbm5Uthz2XJpxrm Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 8/2/24 7:38 PM, Rich Felker wrote: > On Fri, Aug 02, 2024 at 05:27:26PM -0400, Brad House wrote: >> 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) >>       |                                                ^ >> ...       ^ >> >> 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 >> diff --git a/include/netinet/in.h b/include/netinet/in.h >> index fb628b61..f04657f3 100644 >> --- a/include/netinet/in.h >> +++ b/include/netinet/in.h >> @@ -108,46 +108,63 @@ uint16_t ntohs(uint16_t); >> #define IPPROTO_MAX 263 >> >> ... >> #define IN6_IS_ADDR_LOOPBACK(a) \ >> - (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \ >> - ((uint32_t *) (a))[2] == 0 && \ >> - ((uint8_t *) (a))[12] == 0 && ((uint8_t *) (a))[13] == 0 && \ >> - ((uint8_t *) (a))[14] == 0 && ((uint8_t *) (a))[15] == 1 ) >> + (((const uint32_t *) (a))[0] == 0 && \ >> + ((const uint32_t *) (a))[1] == 0 && \ >> + ((const uint32_t *) (a))[2] == 0 && \ >> + ((const uint8_t *) (a))[12] == 0 && \ >> + ((const uint8_t *) (a))[13] == 0 && \ >> + ((const uint8_t *) (a))[14] == 0 && \ >> + ((const uint8_t *) (a))[15] == 1 ) >> ... > It looks like there's a lot wrong with these macros. They should not > be doing random pointer casts like they are. Per the standard, they > take an argument of type const struct in6_addr *, so they should > almost surely be operating on that type directly. That would make them > actually type-safe (diagnostic if called with wrong argument type). > > I guess we should look at whether there's any good reason they were > written the way they were.. > > Rich Yep, I see what you mean.  There are already accessors for 8, 16, and 32bit into struct in6_addr so its odd not to use those.  I've attached a v2 patch that uses those instead which also cleans up the warnings. -Brad --------------tVz02ZdaBDbm5Uthz2XJpxrm Content-Type: text/plain; charset=UTF-8; name="musl-netinet-warning-fix-v2.patch" Content-Disposition: attachment; filename="musl-netinet-warning-fix-v2.patch" Content-Transfer-Encoding: base64 ZGlmZiAtLWdpdCBhL2luY2x1ZGUvbmV0aW5ldC9pbi5oIGIvaW5jbHVkZS9uZXRpbmV0L2lu LmgKaW5kZXggZmI2MjhiNjEuLmM2YWZlZWQ4IDEwMDY0NAotLS0gYS9pbmNsdWRlL25ldGlu ZXQvaW4uaAorKysgYi9pbmNsdWRlL25ldGluZXQvaW4uaApAQCAtMTA4LDUxICsxMDgsNjgg QEAgdWludDE2X3QgbnRvaHModWludDE2X3QpOwogI2RlZmluZSBJUFBST1RPX01BWCAgICAg IDI2MwogCiAjZGVmaW5lIElONl9JU19BRERSX1VOU1BFQ0lGSUVEKGEpIFwKLSAgICAgICAg KCgodWludDMyX3QgKikgKGEpKVswXSA9PSAwICYmICgodWludDMyX3QgKikgKGEpKVsxXSA9 PSAwICYmIFwKLSAgICAgICAgICgodWludDMyX3QgKikgKGEpKVsyXSA9PSAwICYmICgodWlu dDMyX3QgKikgKGEpKVszXSA9PSAwKQorICAgICAgICAoKChhKS0+czZfYWRkcjMyKVswXSA9 PSAwICYmIFwKKyAgICAgICAgICgoYSktPnM2X2FkZHIzMilbMV0gPT0gMCAmJiBcCisgICAg ICAgICAoKGEpLT5zNl9hZGRyMzIpWzJdID09IDAgJiYgXAorICAgICAgICAgKChhKS0+czZf YWRkcjMyKVszXSA9PSAwKQogCiAjZGVmaW5lIElONl9JU19BRERSX0xPT1BCQUNLKGEpIFwK LSAgICAgICAgKCgodWludDMyX3QgKikgKGEpKVswXSA9PSAwICYmICgodWludDMyX3QgKikg KGEpKVsxXSA9PSAwICYmIFwKLSAgICAgICAgICgodWludDMyX3QgKikgKGEpKVsyXSA9PSAw ICYmIFwKLSAgICAgICAgICgodWludDhfdCAqKSAoYSkpWzEyXSA9PSAwICYmICgodWludDhf dCAqKSAoYSkpWzEzXSA9PSAwICYmIFwKLSAgICAgICAgICgodWludDhfdCAqKSAoYSkpWzE0 XSA9PSAwICYmICgodWludDhfdCAqKSAoYSkpWzE1XSA9PSAxICkKKyAgICAgICAgKCgoYSkt PnM2X2FkZHIzMilbMF0gPT0gMCAmJiBcCisgICAgICAgICAoKGEpLT5zNl9hZGRyMzIpWzFd ID09IDAgJiYgXAorICAgICAgICAgKChhKS0+czZfYWRkcjMyKVsyXSA9PSAwICYmIFwKKyAg ICAgICAgICgoYSktPnM2X2FkZHIpWzEyXSA9PSAwICYmIFwKKyAgICAgICAgICgoYSktPnM2 X2FkZHIpWzEzXSA9PSAwICYmIFwKKyAgICAgICAgICgoYSktPnM2X2FkZHIpWzE0XSA9PSAw ICYmIFwKKyAgICAgICAgICgoYSktPnM2X2FkZHIpWzE1XSA9PSAxICkKIAotI2RlZmluZSBJ TjZfSVNfQUREUl9NVUxUSUNBU1QoYSkgKCgodWludDhfdCAqKSAoYSkpWzBdID09IDB4ZmYp CisjZGVmaW5lIElONl9JU19BRERSX01VTFRJQ0FTVChhKSAoKChhKS0+czZfYWRkcilbMF0g PT0gMHhmZikKIAogI2RlZmluZSBJTjZfSVNfQUREUl9MSU5LTE9DQUwoYSkgXAotICAgICAg ICAoKCgodWludDhfdCAqKSAoYSkpWzBdKSA9PSAweGZlICYmICgoKHVpbnQ4X3QgKikgKGEp KVsxXSAmIDB4YzApID09IDB4ODApCisgICAgICAgICgoKChhKS0+czZfYWRkcilbMF0pID09 IDB4ZmUgJiYgXAorICAgICAgICAgKCgoYSktPnM2X2FkZHIpWzFdICYgMHhjMCkgPT0gMHg4 MCkKIAogI2RlZmluZSBJTjZfSVNfQUREUl9TSVRFTE9DQUwoYSkgXAotICAgICAgICAoKCgo dWludDhfdCAqKSAoYSkpWzBdKSA9PSAweGZlICYmICgoKHVpbnQ4X3QgKikgKGEpKVsxXSAm IDB4YzApID09IDB4YzApCisgICAgICAgICgoKChhKS0+czZfYWRkcilbMF0pID09IDB4ZmUg JiYgXAorICAgICAgICAgKCgoYSktPnM2X2FkZHIpWzFdICYgMHhjMCkgPT0gMHhjMCkKIAog I2RlZmluZSBJTjZfSVNfQUREUl9WNE1BUFBFRChhKSBcCi0gICAgICAgICgoKHVpbnQzMl90 ICopIChhKSlbMF0gPT0gMCAmJiAoKHVpbnQzMl90ICopIChhKSlbMV0gPT0gMCAmJiBcCi0g ICAgICAgICAoKHVpbnQ4X3QgKikgKGEpKVs4XSA9PSAwICYmICgodWludDhfdCAqKSAoYSkp WzldID09IDAgJiYgXAotICAgICAgICAgKCh1aW50OF90ICopIChhKSlbMTBdID09IDB4ZmYg JiYgKCh1aW50OF90ICopIChhKSlbMTFdID09IDB4ZmYpCisgICAgICAgICgoKGEpLT5zNl9h ZGRyMzIpWzBdID09IDAgJiYgXAorICAgICAgICAgKChhKS0+czZfYWRkcjMyKVsxXSA9PSAw ICYmIFwKKyAgICAgICAgICgoYSktPnM2X2FkZHIpWzhdID09IDAgJiYgXAorICAgICAgICAg KChhKS0+czZfYWRkcilbOV0gPT0gMCAmJiBcCisgICAgICAgICAoKGEpLT5zNl9hZGRyKVsx MF0gPT0gMHhmZiAmJiBcCisgICAgICAgICAoKGEpLT5zNl9hZGRyKVsxMV0gPT0gMHhmZikK IAogI2RlZmluZSBJTjZfSVNfQUREUl9WNENPTVBBVChhKSBcCi0gICAgICAgICgoKHVpbnQz Ml90ICopIChhKSlbMF0gPT0gMCAmJiAoKHVpbnQzMl90ICopIChhKSlbMV0gPT0gMCAmJiBc Ci0gICAgICAgICAoKHVpbnQzMl90ICopIChhKSlbMl0gPT0gMCAmJiAoKHVpbnQ4X3QgKikg KGEpKVsxNV0gPiAxKQorICAgICAgICAoKChhKS0+czZfYWRkcjMyKVswXSA9PSAwICYmIFwK KyAgICAgICAgICgoYSktPnM2X2FkZHIzMilbMV0gPT0gMCAmJiBcCisgICAgICAgICAoKGEp LT5zNl9hZGRyMzIpWzJdID09IDAgJiYgXAorICAgICAgICAgKChhKS0+czZfYWRkcilbMTVd ID4gMSkKIAogI2RlZmluZSBJTjZfSVNfQUREUl9NQ19OT0RFTE9DQUwoYSkgXAotICAgICAg ICAoSU42X0lTX0FERFJfTVVMVElDQVNUKGEpICYmICgoKCh1aW50OF90ICopIChhKSlbMV0g JiAweGYpID09IDB4MSkpCisgICAgICAgIChJTjZfSVNfQUREUl9NVUxUSUNBU1QoYSkgJiYg XAorICAgICAgICAgKCgoKGEpLT5zNl9hZGRyKVsxXSAmIDB4ZikgPT0gMHgxKSkKIAogI2Rl ZmluZSBJTjZfSVNfQUREUl9NQ19MSU5LTE9DQUwoYSkgXAotICAgICAgICAoSU42X0lTX0FE RFJfTVVMVElDQVNUKGEpICYmICgoKCh1aW50OF90ICopIChhKSlbMV0gJiAweGYpID09IDB4 MikpCisgICAgICAgIChJTjZfSVNfQUREUl9NVUxUSUNBU1QoYSkgJiYgXAorICAgICAgICAg KCgoKGEpLT5zNl9hZGRyKVsxXSAmIDB4ZikgPT0gMHgyKSkKIAogI2RlZmluZSBJTjZfSVNf QUREUl9NQ19TSVRFTE9DQUwoYSkgXAotICAgICAgICAoSU42X0lTX0F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