diff --git a/include/beast/websocket/detail/hybi13.hpp b/include/beast/websocket/detail/hybi13.hpp index 154e8582..72999f68 100644 --- a/include/beast/websocket/detail/hybi13.hpp +++ b/include/beast/websocket/detail/hybi13.hpp @@ -23,15 +23,17 @@ template std::string make_sec_ws_key(Gen& g) { - union U + std::array a; + for(int i = 0; i < 16; i += 4) { - std::array a4; - std::array a16; - }; - U u; - for(int i = 0; i < 4; ++i) - u.a4[i] = g(); - return beast::detail::base64_encode(u.a16.data(), u.a16.size()); + auto const v = g(); + a[i ] = v & 0xff; + a[i+1] = (v >> 8) & 0xff; + a[i+2] = (v >> 16) & 0xff; + a[i+3] = (v >> 24) & 0xff; + } + return beast::detail::base64_encode( + a.data(), a.size()); } template