[systemd-devel] [PATCH] Fix compilation under clang/LLVM

Dan McGee dan at archlinux.org
Tue Aug 5 17:58:47 PDT 2014


Compilation is failing because we are doing something not allowed by the
language spec, but OK by GCC extensions in our MAX() macro.

src/resolve/resolved-manager.c:759:43: error: non-const static data member must be initialized out of line
                uint8_t buffer[CMSG_SPACE(MAX(sizeof(struct in_pktinfo), sizeof(struct in6_pktinfo)))
                                          ^

Add a new constant that does this in a way both compilers are OK with,
since we know all factors in the size computation are static.
---

A longer list of the compile errors: https://paste.xinu.at/RMRdv1/

 src/resolve/resolved-dns-stream.c | 2 +-
 src/resolve/resolved-manager.c    | 2 +-
 src/resolve/resolved-manager.h    | 1 +
 3 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/resolve/resolved-dns-stream.c b/src/resolve/resolved-dns-stream.c
index eb78587..dbcacaa 100644
--- a/src/resolve/resolved-dns-stream.c
+++ b/src/resolve/resolved-dns-stream.c
@@ -64,7 +64,7 @@ static int dns_stream_complete(DnsStream *s, int error) {
 static int dns_stream_identify(DnsStream *s) {
         union {
                 struct cmsghdr header; /* For alignment */
-                uint8_t buffer[CMSG_SPACE(MAX(sizeof(struct in_pktinfo), sizeof(struct in6_pktinfo)))
+                uint8_t buffer[PKTINFO_CMSG_SPACE
                                + EXTRA_CMSG_SPACE /* kernel appears to require extra space */];
         } control;
         struct msghdr mh = {};
diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c
index 1288395..75a143d 100644
--- a/src/resolve/resolved-manager.c
+++ b/src/resolve/resolved-manager.c
@@ -756,7 +756,7 @@ int manager_recv(Manager *m, int fd, DnsProtocol protocol, DnsPacket **ret) {
         _cleanup_(dns_packet_unrefp) DnsPacket *p = NULL;
         union {
                 struct cmsghdr header; /* For alignment */
-                uint8_t buffer[CMSG_SPACE(MAX(sizeof(struct in_pktinfo), sizeof(struct in6_pktinfo)))
+                uint8_t buffer[PKTINFO_CMSG_SPACE
                                + CMSG_SPACE(int) /* ttl/hoplimit */
                                + EXTRA_CMSG_SPACE /* kernel appears to require extra buffer space */];
         } control;
diff --git a/src/resolve/resolved-manager.h b/src/resolve/resolved-manager.h
index 9d824e1..5cffd9b 100644
--- a/src/resolve/resolved-manager.h
+++ b/src/resolve/resolved-manager.h
@@ -147,6 +147,7 @@ int manager_our_packet(Manager *m, DnsPacket *p);
 
 DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
 
+#define PKTINFO_CMSG_SPACE CMSG_SPACE(sizeof(struct in_pktinfo) > sizeof(struct in6_pktinfo) ? sizeof(struct in_pktinfo) : sizeof(struct in6_pktinfo))
 #define EXTRA_CMSG_SPACE 1024
 
 const char* support_to_string(Support p) _const_;
-- 
2.0.4



More information about the systemd-devel mailing list