TraversalClient: Prevent uninitialized values from occurring in MakeENetAddress

Previously, eaddr would only be partially initialized in the ipv6 case.
Even if there's no support for it, we may as well ensure that the
variable always has deterministic initialization.

While we're at it, we can make the parameter a const reference, given no
members are modified.
This commit is contained in:
Lioncash 2021-01-19 14:21:04 -05:00
parent f0c6e696fd
commit cb4ca7837a
1 changed files with 7 additions and 7 deletions

View File

@ -58,17 +58,17 @@ void TraversalClient::ReconnectToServer()
m_Client->OnTraversalStateChanged();
}
static ENetAddress MakeENetAddress(TraversalInetAddress* address)
static ENetAddress MakeENetAddress(const TraversalInetAddress& address)
{
ENetAddress eaddr;
if (address->isIPV6)
ENetAddress eaddr{};
if (address.isIPV6)
{
eaddr.port = 0; // no support yet :(
}
else
{
eaddr.host = address->address[0];
eaddr.port = ntohs(address->port);
eaddr.host = address.address[0];
eaddr.port = ntohs(address.port);
}
return eaddr;
}
@ -160,7 +160,7 @@ void TraversalClient::HandleServerPacket(TraversalPacket* packet)
case TraversalPacketType::PleaseSendPacket:
{
// security is overrated.
ENetAddress addr = MakeENetAddress(&packet->pleaseSendPacket.address);
ENetAddress addr = MakeENetAddress(packet->pleaseSendPacket.address);
if (addr.port != 0)
{
char message[] = "Hello from Dolphin Netplay...";
@ -188,7 +188,7 @@ void TraversalClient::HandleServerPacket(TraversalPacket* packet)
break;
if (packet->type == TraversalPacketType::ConnectReady)
m_Client->OnConnectReady(MakeENetAddress(&packet->connectReady.address));
m_Client->OnConnectReady(MakeENetAddress(packet->connectReady.address));
else
m_Client->OnConnectFailed(packet->connectFailed.reason);
break;