From mboxrd@z Thu Jan 1 00:00:00 1970 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_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 17974 invoked from network); 16 Feb 2022 20:27:24 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 16 Feb 2022 20:27:24 -0000 Received: (qmail 30566 invoked by uid 550); 16 Feb 2022 20:27:22 -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 30534 invoked from network); 16 Feb 2022 20:27:21 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=/4IHPIs1lljS25BQBCvY5nCnf5D4cY8rR/xFEHoQORY=; b=K7LbmQS2YODaYhnI25+pCuzjYvxUpGAz5l2GO1721gNYVzW6jLfynuenXkXSed/W6n J/yjPpZN7vrVcOIb0RuVRTxFiq6xy3+OmmdKdrAASDw4jsaTcZoZFXY/8a27KmWVYwhg xgkAc6vWtHjri/ztV8w+uWzfsB1xTXlLfWSSfJr1hNbhHWS+mpQiIiU/j63dBX53jwgp HOkOo+DplxH6eQZPSe6Nvzu5fI8F0SqtfGSqIp2Ma6OChMg+dc/v9wEnRe5mtQqN7sMJ R+XVA10R/Dpxwk7p8V7GXSVLuOh038tstXU9a+ym9nK9fRD0Uot8Yv5ml7lDfV10s3Iq B6aQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=/4IHPIs1lljS25BQBCvY5nCnf5D4cY8rR/xFEHoQORY=; b=t4IppIUYIse+yr1u0OGDuHvIKqZUnaYD7WlUwlRW5MtltQqaDKuVxDgYXRCmvDbSir 9h3t968aWynlYRliIT7VuBvEDeCUgmAUt6dLcMwpc26auproiXNvQcy+JBX65Vc78l9c Jp2yqVtd7zoKQl0PHv6BsWr9iSGhj8B3k3tGO1snZ9H0ax6tJgiLn6FWWMz9wAShmaRj ayZjWFEbD0BqzF8koCOSyMXsPL7RvbP3AXXsWPfyPCVjxmdTOLVSDIwXYV5p8KOMSUuk YGL5LMGV8M9pM88EU0iARSCczMZrsjRD+gBDkEOckTXHMXocEsx2vVrFzjIp9C88kyzH c31Q== X-Gm-Message-State: AOAM530FYCWiXleefDOfnZswDIMyCNuIyUO1axrwhsmlqfRumwP25FCD aVwz9nLSgypLJCARLUZVudVfl4ZpdeZbwI2cfpb7y6ujM+mQQL0+TT1Nd8XsGiqma29BT2CFf4P 8L0M7vq5LumfII3k5+fTmMcIn17gYFEb/fMS2TCgGoDTTwAXEKWvsjp+Zt+wbYzg= X-Google-Smtp-Source: ABdhPJwqzPUoBU34PQdPz8aHtcuY+r61lALjzz5ksvylM+FN6RbaPaXnxlHgLby+87mn3HRjrWzkP7X7NFk= X-Received: from walnut.mtv.corp.google.com ([2620:15c:211:202:b3df:b9c7:5119:53d0]) (user=ccross job=sendgmr) by 2002:a81:33d6:0:b0:2cf:899f:2b70 with SMTP id z205-20020a8133d6000000b002cf899f2b70mr4049470ywz.155.1645043229547; Wed, 16 Feb 2022 12:27:09 -0800 (PST) Date: Wed, 16 Feb 2022 12:27:05 -0800 Message-Id: <20220216202705.2173894-1-ccross@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.35.1.265.g69c8d7142f-goog From: Colin Cross To: musl@lists.openwall.com Cc: Christian Eggers , Colin Cross Content-Type: text/plain; charset="UTF-8" Subject: [musl] [PATCH] Work around -Wcast-align and -Wsign-compare warnings in sys/socket.h Clang produces -Wcast-align and -Wsign-compare warnings when using CMSG_NXTHDR: ./nettest.cpp:5:12: warning: cast from 'unsigned char *' to 'struct cmsghdr *' increases required alignment from 1 to 4 [-Wcast-align] return CMSG_NXTHDR(mhdr, cmsg); ^~~~~~~~~~~~~~~~~~~~~~~ /usr/include/sys/socket.h:270:8: note: expanded from macro 'CMSG_NXTHDR' ? 0 : (struct cmsghdr *)__CMSG_NEXT(cmsg)) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ./nettest.cpp:5:12: warning: comparison of integers of different signs: 'unsigned long' and 'long' [-Wsign-compare] return CMSG_NXTHDR(mhdr, cmsg); ^~~~~~~~~~~~~~~~~~~~~~~ /usr/include/sys/socket.h:269:44: note: expanded from macro 'CMSG_NXTHDR' __CMSG_LEN(cmsg) + sizeof(struct cmsghdr) >= __MHDR_END(mhdr) - (unsigned char *)(cmsg) \ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2 warnings generated. Clang should really be hiding the warnings when the header is included from a directory specified with -isystem, but it doesn't. This has resulted in patches to many projects work around the issue: https://github.com/openembedded/meta-openembedded/commit/cfa3f070885482dc2f0c3e13fe70f20fad46e35e https://github.com/openembedded/meta-openembedded/commit/cfb432a714457d2fd66a02fe7f1340094742ba69 https://github.com/dotnet/corefx/pull/6263 https://github.com/dotnet/corefx/pull/12520 It also occurs in the Android codebase in multiple projects. It has come up on the mailing list multiple times: https://www.openwall.com/lists/musl/2016/10/10/1 https://www.openwall.com/lists/musl/2018/03/06/4 https://www.openwall.com/lists/musl/2022/02/16/7 Pragmatically work around the clang bug by fixing the warnings, casting through void * to avoid the -Wcast-align warning and casting to size_t to avoid the -Wsign-compare warning. --- include/sys/socket.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/sys/socket.h b/include/sys/socket.h index 38f5bb17..b604f6cd 100644 --- a/include/sys/socket.h +++ b/include/sys/socket.h @@ -353,8 +353,8 @@ struct linger { #define CMSG_DATA(cmsg) ((unsigned char *) (((struct cmsghdr *)(cmsg)) + 1)) #define CMSG_NXTHDR(mhdr, cmsg) ((cmsg)->cmsg_len < sizeof (struct cmsghdr) || \ - __CMSG_LEN(cmsg) + sizeof(struct cmsghdr) >= __MHDR_END(mhdr) - (unsigned char *)(cmsg) \ - ? 0 : (struct cmsghdr *)__CMSG_NEXT(cmsg)) + __CMSG_LEN(cmsg) + sizeof(struct cmsghdr) >= (size_t)(__MHDR_END(mhdr) - (unsigned char *)(cmsg)) \ + ? 0 : (struct cmsghdr *)(void *)__CMSG_NEXT(cmsg)) #define CMSG_FIRSTHDR(mhdr) ((size_t) (mhdr)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (mhdr)->msg_control : (struct cmsghdr *) 0) #define CMSG_ALIGN(len) (((len) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)) -- 2.35.1.265.g69c8d7142f-goog