diff --git a/ixwebsocket/IXWebSocket.cpp b/ixwebsocket/IXWebSocket.cpp index e0815ad3..1675533e 100644 --- a/ixwebsocket/IXWebSocket.cpp +++ b/ixwebsocket/IXWebSocket.cpp @@ -15,6 +15,12 @@ #include +namespace +{ + const std::string emptyMsg; +} // namespace + + namespace ix { OnTrafficTrackerCallback WebSocket::_onTrafficTrackerCallback = nullptr; @@ -38,7 +44,7 @@ namespace ix [this](uint16_t code, const std::string& reason, size_t wireSize, bool remote) { _onMessageCallback( ix::make_unique(WebSocketMessageType::Close, - "", + emptyMsg, wireSize, WebSocketErrorInfo(), WebSocketOpenInfo(), @@ -217,7 +223,7 @@ namespace ix _onMessageCallback(ix::make_unique( WebSocketMessageType::Open, - "", + emptyMsg, 0, WebSocketErrorInfo(), WebSocketOpenInfo(status.uri, status.headers, status.protocol), @@ -251,7 +257,7 @@ namespace ix _onMessageCallback( ix::make_unique(WebSocketMessageType::Open, - "", + emptyMsg, 0, WebSocketErrorInfo(), WebSocketOpenInfo(status.uri, status.headers), @@ -338,7 +344,7 @@ namespace ix connectErr.http_status = status.http_status; _onMessageCallback(ix::make_unique(WebSocketMessageType::Error, - "", + emptyMsg, 0, connectErr, WebSocketOpenInfo(), diff --git a/ixwebsocket/IXWebSocketMessage.h b/ixwebsocket/IXWebSocketMessage.h index ae07d38c..25a00ce7 100644 --- a/ixwebsocket/IXWebSocketMessage.h +++ b/ixwebsocket/IXWebSocketMessage.h @@ -42,6 +42,18 @@ namespace ix { ; } + + /** + * @brief Deleted overload to prevent binding `str` to a temporary, which would cause + * undefined behavior since class members don't extend lifetime beyond the constructor call. + */ + WebSocketMessage(WebSocketMessageType t, + std::string&& s, + size_t w, + WebSocketErrorInfo e, + WebSocketOpenInfo o, + WebSocketCloseInfo c, + bool b = false) = delete; }; using WebSocketMessagePtr = std::unique_ptr;