From 8513e594310af03df7613fb3255b6ca5cd84710d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Holz?= Date: Fri, 13 Aug 2021 00:37:03 +0200 Subject: [PATCH] network: narrow down scope of "result" in win32 code for GetAvailableNetworkInterfaces --- src/core/network/network_interface.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/core/network/network_interface.cpp b/src/core/network/network_interface.cpp index 887aee708..34e20f547 100644 --- a/src/core/network/network_interface.cpp +++ b/src/core/network/network_interface.cpp @@ -22,8 +22,6 @@ namespace Network { #ifdef _WIN32 std::vector GetAvailableNetworkInterfaces() { - std::vector result; - std::vector adapter_addresses_raw; auto adapter_addresses = reinterpret_cast(adapter_addresses_raw.data()); DWORD ret = ERROR_BUFFER_OVERFLOW; @@ -44,6 +42,8 @@ std::vector GetAvailableNetworkInterfaces() { } if (ret == NO_ERROR) { + std::vector result; + for (auto current_address = adapter_addresses; current_address != nullptr; current_address = current_address->Next) { if (current_address->FirstUnicastAddress == nullptr || @@ -63,11 +63,12 @@ std::vector GetAvailableNetworkInterfaces() { .name{Common::UTF16ToUTF8(std::wstring{current_address->FriendlyName})}, .ip_address{ip_addr}}); } + + return result; } else { LOG_ERROR(Network, "Failed to get network interfaces with GetAdaptersAddresses"); + return {}; } - - return result; } #else