|
|
Message-ID: <CANeUF6GGyYM30G=afDk3stWQL1iibfmW_BE5=ZBATSWG9E5SYw@mail.gmail.com>
Date: Tue, 17 Mar 2026 23:33:31 +0100
From: Jérémy PRIMARD <jeremy.primard01@...il.com>
To: musl@...ts.openwall.com
Subject: [PATCH] sys/socket.h: Fixed -Wsign-compare in musl CMSG_NXTHDR() macro
__CMSG_LEN(cmsg) is an unsigned long
sizeof(struct cmsghdr) is an unsigned long
So __CMSG_LEN(cmsg) + sizeof(struct cmsghdr) is also an unsigned long
__MHDR_END(mhdr) is an unsigned char pointer
(unsigned char *)(cmsg) is also an unsigned char pointer
so __MHDR_END(mhdr) - (unsigned char *)(cmsg) will not result in an
unsigned long, but in a signed long. The compiler think that there
is a world where the result can be negative, so we needs to
explicitely state that the result is unsigned.
---
include/sys/socket.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/sys/socket.h b/include/sys/socket.h
index 6dc1e40a..b1a56483 100644
--- a/include/sys/socket.h
+++ b/include/sys/socket.h
@@ -355,7 +355,7 @@ 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) \
+ __CMSG_LEN(cmsg) + sizeof(struct cmsghdr) >= (unsigned
long)(__MHDR_END(mhdr) - (unsigned char *)(cmsg)) \
? 0 : (struct cmsghdr *)__CMSG_NEXT(cmsg))
#define CMSG_FIRSTHDR(mhdr) ((size_t) (mhdr)->msg_controllen >=
sizeof (struct cmsghdr) ? (struct cmsghdr *) (mhdr)->msg_control :
(struct cmsghdr *) 0)
--
2.53.0
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.