Fix unsafe calls and safeguard WebSocketMessage (#294)

* Fix unsafe calls and safeguard WebSocketMessage from being called w/
temporaries

* Use unnamed namespace to express internal linkage
This commit is contained in:
Nikos Athanasiou
2021-06-04 04:39:38 +03:00
committed by GitHub
parent e3c98a03cc
commit 26897b2425
2 changed files with 22 additions and 4 deletions

View File

@ -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<WebSocketMessage>;