Skip to content

Commit

Permalink
Socket: make m_address and m_remoteEndpoint members non-const.
Browse files Browse the repository at this point in the history
This avoids needing const_cast conversions when modifying them, which
is actually undefined behavior in C++ because we were modifying a const
object.
  • Loading branch information
evil-at-wow authored and killerwife committed Sep 27, 2023
1 parent 3f60957 commit 70e1611
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/shared/Network/Socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ namespace MaNGOS
{
try
{
const_cast<std::string&>(m_address) = m_socket.remote_endpoint().address().to_string();
const_cast<std::string&>(m_remoteEndpoint) = boost::lexical_cast<std::string>(m_socket.remote_endpoint());
m_address = m_socket.remote_endpoint().address().to_string();
m_remoteEndpoint = boost::lexical_cast<std::string>(m_socket.remote_endpoint());
m_remoteAddress = m_socket.remote_endpoint().address();
m_remotePort = m_socket.remote_endpoint().port();
}
Expand Down
4 changes: 2 additions & 2 deletions src/shared/Network/Socket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ namespace MaNGOS
void OnError(const boost::system::error_code &error);

protected:
const std::string m_address;
const std::string m_remoteEndpoint;
std::string m_address;
std::string m_remoteEndpoint;
boost::asio::ip::address m_remoteAddress;
uint16 m_remotePort;

Expand Down

0 comments on commit 70e1611

Please sign in to comment.