]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Fix builds on compilers without anonymous union support
authorSteffan Karger <steffan@karger.me>
Sun, 13 Nov 2016 18:03:23 +0000 (19:03 +0100)
committerGert Doering <gert@greenie.muc.de>
Sun, 13 Nov 2016 18:24:47 +0000 (19:24 +0100)
The "Don't dereference type-punned pointers" patch introduced an anonymous
union, which older compilers do not support (or refuse to support when
-std=c99 is defined).  Add a configure check, and some wrapper defines to
repair builds on those compilers.

Signed-off-by: Steffan Karger <steffan@karger.me>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <1479060203-4472-1-git-send-email-steffan@karger.me>
URL: http://www.mail-archive.com/search?l=mid&q=1479060203-4472-1-git-send-email-steffan@karger.me
Signed-off-by: Gert Doering <gert@greenie.muc.de>
configure.ac
src/openvpn/mroute.h

index e44f619330b743e0f82e018fe2f38796ee09a93f..18c772d6235fb1cc4183ee22af1f8663cd6f2d0f 100644 (file)
@@ -390,6 +390,12 @@ AC_DEFINE_UNQUOTED([IPROUTE_PATH], ["$IPROUTE"], [Path to iproute tool])
 AC_DEFINE_UNQUOTED([ROUTE_PATH], ["$ROUTE"], [Path to route tool])
 AC_DEFINE_UNQUOTED([SYSTEMD_ASK_PASSWORD_PATH], ["$SYSTEMD_ASK_PASSWORD"], [Path to systemd-ask-password tool])
 
+# Set -std=c99 unless user already specified a -std=
+case "${CFLAGS}" in
+  *-std=*) ;;
+  *)       CFLAGS="${CFLAGS} -std=c99" ;;
+esac
+
 #
 # Libtool
 #
@@ -553,6 +559,28 @@ AC_CHECK_DECLS(
        ,
        [[${SOCKET_INCLUDES}]]
 )
+AC_CHECKING([anonymous union support])
+AC_COMPILE_IFELSE(
+       [AC_LANG_PROGRAM(
+               [[
+                       struct mystruct {
+                         union {
+                           int m1;
+                           char m2;
+                         };
+                       };
+               ]],
+               [[
+                       struct mystruct s;
+                       s.m1 = 1; s.m2 = 2;
+               ]]
+       )],
+       [
+               AC_MSG_RESULT([yes])
+               AC_DEFINE([HAVE_ANONYMOUS_UNION_SUPPORT], [], [Compiler supports anonymous unions])
+       ],
+       [AC_MSG_RESULT([no])]
+)
 
 dnl We emulate signals in Windows
 AC_CHECK_DECLS(
@@ -1148,12 +1176,6 @@ if test "${enable_pkcs11}" = "yes"; then
        )
 fi
 
-# Set -std=c99 unless user already specified a -std=
-case "${CFLAGS}" in
-  *-std=*) ;;
-  *)       CFLAGS="${CFLAGS} -std=c99" ;;
-esac
-
 if test "${enable_pedantic}" = "yes"; then
        enable_strict="yes"
        CFLAGS="${CFLAGS} -pedantic"
index 5fe17e7f31e9f2e777873d095fae3ed1344b5178..8f7a064231fb8917531081c227c8c0877dd84cf0 100644 (file)
@@ -96,7 +96,17 @@ struct mroute_addr {
       uint8_t prefix[12];
       in_addr_t addr;          /* _network order_ IPv4 address */
     } v4mappedv6;
-  };
+  }
+#ifndef HAVE_ANONYMOUS_UNION_SUPPORT
+/* Wrappers to support compilers that do not grok anonymous unions */
+  mroute_union
+#define raw_addr mroute_union.raw_addr
+#define eth_addr mroute_union.eth_addr
+#define v4 mroute_union.v4
+#define v6 mroute_union.v6
+#define v4mappedv6 mroute_union.v4mappedv6
+#endif
+  ;
 };
 
 /* Double-check that struct packing works as expected */