machinezone / IXWebSocket

websocket and http client and server library, with TLS support and very few dependencies
BSD 3-Clause "New" or "Revised" License
539 stars 173 forks source link

Possible unintentional copying inside Websocket#connect function #509

Closed Longwater1234 closed 6 months ago

Longwater1234 commented 6 months ago

On latest release version ( 11.4.5) .I noticed this inside WebSocket::connect(int timeout) function (IXWebSocket.cpp, lines 210), mulitiple copying which may be unintentional. Please see the snippet below. Could be fixed by using References instead.

WebSocketHttpHeaders headers(_extraHeaders);
std::string subProtocolsHeader;
// FIXME here subProtocols vector is copied
auto subProtocols = getSubProtocols();
if (!subProtocols.empty())
{

    int i = 0;
// FIXME here subProtocol is copied
    for (auto subProtocol : subProtocols)
    {
        if (i++ != 0)
        {
            subProtocolsHeader += ",";
        }
        subProtocolsHeader += subProtocol;
    }
    headers["Sec-WebSocket-Protocol"] = subProtocolsHeader;
}
bsergean commented 6 months ago

Thanks for checkin ; 92beef83484f4d9bf216ab1ed3775b9eefc89cc4 should avoid this.