summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaphael Kubo da Costa <rakuco@FreeBSD.org>2012-09-11 22:50:18 +0300
committerChristian Beier <dontmind@freeshell.org>2012-09-14 18:47:53 +0200
commit8f544bd276fcabc52d3816fb0814229805c8d198 (patch)
treed0024f56d7b15410af3af86deaf36f4192f35f9e
parenta63312c6fbb26dffdaf9ab05b89a34bf7591e7d9 (diff)
downloadlibtdevnc-8f544bd2.tar.gz
libtdevnc-8f544bd2.zip
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
-rw-r--r--libvncserver/websockets.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/libvncserver/websockets.c b/libvncserver/websockets.c
index f56b002..10743fe 100644
--- a/libvncserver/websockets.c
+++ b/libvncserver/websockets.c
@@ -94,6 +94,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;
@@ -101,13 +106,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
@@ -686,15 +691,15 @@ webSocketsDecodeHybi(rfbClientPtr cl, char *dst, int len)
if (flength < 126) {
fhlen = 2;
- mask = header->m;
+ mask = header->u.m;
} else if (flength == 126 && 4 <= ret) {
- flength = WS_NTOH16(header->l16);
+ flength = WS_NTOH16(header->u.s16.l16);
fhlen = 4;
- mask = header->m16;
+ mask = header->u.s16.m16;
} else if (flength == 127 && 10 <= ret) {
- flength = WS_NTOH64(header->l64);
+ flength = WS_NTOH64(header->u.s64.l64);
fhlen = 10;
- mask = header->m64;
+ mask = header->u.s64.m64;
} else {
/* Incomplete frame header */
rfbErr("%s: incomplete frame header\n", __func__, ret);
@@ -798,11 +803,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;
}