Blob Blame History Raw
From a6e141517b86a866feba4d472ead02a9df569a9e Mon Sep 17 00:00:00 2001
From: Raphael Kubo da Costa <rakuco@FreeBSD.org>
Date: Tue, 11 Sep 2012 22:50:18 +0300
Subject: [PATCH 1/3] Work around a gcc bug with anonymous structs and unions.

GCC < 4.6 failed to parse the declaration of ws_header_t correctly because
it did not accept anonymous structs and unions. [1]

Work around the bug by adding names to the unions and structs. Ugly, but
works.

[1] http://gcc.gnu.org/bugzilla/show_bug.cgi?id=4784
---
 libvncserver/websockets.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/libvncserver/websockets.c b/libvncserver/websockets.c
index 8cd96d38..937f6d4d 100644
--- a/libvncserver/websockets.c
+++ b/libvncserver/websockets.c
@@ -88,6 +88,11 @@ typedef union ws_mask_s {
   uint32_t u;
 } ws_mask_t;
 
+/* XXX: The union and the structs do not need to be named.
+ *      We are working around a bug present in GCC < 4.6 which prevented
+ *      it from recognizing anonymous structs and unions.
+ *      See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=4784
+ */
 typedef struct __attribute__ ((__packed__)) ws_header_s {
   unsigned char b0;
   unsigned char b1;
@@ -95,13 +100,13 @@ typedef struct __attribute__ ((__packed__)) ws_header_s {
     struct __attribute__ ((__packed__)) {
       uint16_t l16;
       ws_mask_t m16;
-    };
+    } s16;
     struct __attribute__ ((__packed__)) {
       uint64_t l64;
       ws_mask_t m64;
-    };
+    } s64;
     ws_mask_t m;
-  };
+  } u;
 } ws_header_t;
 
 enum
@@ -792,11 +797,11 @@ webSocketsEncodeHybi(rfbClientPtr cl, const char *src, int len, char **dst)
       sz = 2;
     } else if (blen <= 65536) {
       header->b1 = 0x7e;
-      header->l16 = WS_HTON16((uint16_t)blen);
+      header->u.s16.l16 = WS_HTON16((uint16_t)blen);
       sz = 4;
     } else {
       header->b1 = 0x7f;
-      header->l64 = WS_HTON64(blen);
+      header->u.s64.l64 = WS_HTON64(blen);
       sz = 10;
     }
 
-- 
2.26.2