CppServer icon indicating copy to clipboard operation
CppServer copied to clipboard

size_t, 32 or 64 bits

Open sadeghitk opened this issue 5 years ago • 0 comments

Observation, Looking at the code ws.cpp (and other ones). The "size_t" used all over. I guess the assumption is, the compiler will be 32 or 64 environment.

ws.h size_t _ws_payload_size{0}; if used in 32 bit environment will not work as intended and will have side effects.

payload = (((size_t)_ws_receive_buffer[2] << 56) | ((size_t)_ws_receive_buffer[3] << 48) | ((size_t)_ws_receive_buffer[4] << 40) | ((size_t)_ws_receive_buffer[5] << 32) | ((size_t)_ws_receive_buffer[6] << 24) | ((size_t)_ws_receive_buffer[7] << 16) | ((size_t)_ws_receive_buffer[8] << 8) | ((size_t)_ws_receive_buffer[9] << 0)); _ws_header_size = 10 + (mask ? 4 : 0); _ws_payload_size = payload;

It is preferable to explicitly define the "payload" to be "unsigned int 64 bit", as protocol call for.

sadeghitk avatar Jul 13 '20 19:07 sadeghitk