From b13178f0ac40dfd700be94b2952f17dd9e3c172c Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Wed, 15 Jul 2015 22:22:23 +0100 Subject: [PATCH] Cast pointer conversions through void We are taking a char * and casting it to uint32_t or uint16_t. This increases the required alignment to 4 and 2 respectively. On most platforms alignment of 16bits is enough and we are writing to offsets that a divisable by 2 so we shouldn't have any segmentation faults. --- src/civetweb.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/civetweb.c b/src/civetweb.c index ff1e1214..47b9c130 100755 --- a/src/civetweb.c +++ b/src/civetweb.c @@ -7136,8 +7136,8 @@ static void read_websocket(struct mg_connection *conn, data_len = ((((size_t)buf[2]) << 8) + buf[3]); } else if (body_len >= 10 + mask_len) { header_len = 10 + mask_len; - data_len = (((uint64_t)ntohl(*(uint32_t *)&buf[2])) << 32) + - ntohl(*(uint32_t *)&buf[6]); + data_len = (((uint64_t)ntohl(*(uint32_t *)(void *)&buf[2])) << 32) + + ntohl(*(uint32_t *)(void *)&buf[6]); } } @@ -7266,13 +7266,13 @@ int mg_websocket_write(struct mg_connection *conn, } else if (dataLen <= 0xFFFF) { /* 16-bit length field */ header[1] = 126; - *(uint16_t *)(header + 2) = htons((uint16_t)dataLen); + *(uint16_t *)(void *)(header + 2) = htons((uint16_t)dataLen); headerLen = 4; } else { /* 64-bit length field */ header[1] = 127; - *(uint32_t *)(header + 2) = htonl((uint64_t)dataLen >> 32); - *(uint32_t *)(header + 6) = htonl(dataLen & 0xFFFFFFFF); + *(uint32_t *)(void *)(header + 2) = htonl((uint64_t)dataLen >> 32); + *(uint32_t *)(void *)(header + 6) = htonl(dataLen & 0xFFFFFFFF); headerLen = 10; }