From cb4ca7837a5a1bd97627b73962823ad6f207fadc Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 19 Jan 2021 14:21:04 -0500 Subject: [PATCH] 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. --- Source/Core/Common/TraversalClient.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Source/Core/Common/TraversalClient.cpp b/Source/Core/Common/TraversalClient.cpp index 4bcde96f6e..19014932a4 100644 --- a/Source/Core/Common/TraversalClient.cpp +++ b/Source/Core/Common/TraversalClient.cpp @@ -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;