From da93666cd836ab679b3370f031f6efb36a5b2574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomas=20Hellstr=C3=B6m?= Date: Tue, 19 Jan 2021 10:42:59 +0100 Subject: [PATCH] x.websocket: bring back shift operators (#8197) --- vlib/x/websocket/message.v | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/vlib/x/websocket/message.v b/vlib/x/websocket/message.v index bb7b58b310..8dcb5fa0d4 100644 --- a/vlib/x/websocket/message.v +++ b/vlib/x/websocket/message.v @@ -1,7 +1,6 @@ module websocket import encoding.utf8 -import math const ( header_len_offset = 2 // offset for lengthpart of websocket header @@ -254,7 +253,7 @@ pub fn (mut ws Client) parse_frame_header() ?Frame { if frame.payload_len == 126 && bytes_read == u64(extended_payload16_end_byte) { frame.header_len += 2 frame.payload_len = 0 - frame.payload_len |= (buffer[2] * int(math.pow(2, 8))) + frame.payload_len |= buffer[2] << 8 frame.payload_len |= buffer[3] frame.frame_size = frame.header_len + frame.payload_len if !frame.has_mask { @@ -263,15 +262,17 @@ pub fn (mut ws Client) parse_frame_header() ?Frame { } if frame.payload_len == 127 && bytes_read == u64(extended_payload64_end_byte) { frame.header_len += 8 - frame.payload_len = 0 - frame.payload_len |= (buffer[2] * int(math.pow(2, 56))) - frame.payload_len |= (buffer[3] * int(math.pow(2, 48))) - frame.payload_len |= (buffer[4] * int(math.pow(2, 40))) - frame.payload_len |= (buffer[5] * int(math.pow(2, 32))) - frame.payload_len |= (buffer[6] * int(math.pow(2, 24))) - frame.payload_len |= (buffer[7] * int(math.pow(2, 16))) - frame.payload_len |= (buffer[8] * int(math.pow(2, 8))) - frame.payload_len |= buffer[9] + // these shift operators needs 64 bit on clang with -prod flag + mut payload_len := u64(0) + payload_len |= buffer[2] << 56 + payload_len |= buffer[3] << 48 + payload_len |= buffer[4] << 40 + payload_len |= buffer[5] << 32 + payload_len |= buffer[6] << 24 + payload_len |= buffer[7] << 16 + payload_len |= buffer[8] << 8 + payload_len |= buffer[9] + frame.payload_len = int(payload_len) if !frame.has_mask { break }