From deb65a5717036c4f6497d4102082921352dfcda0 Mon Sep 17 00:00:00 2001 From: spholz <44805808+spholz@users.noreply.github.com> Date: Fri, 13 Aug 2021 11:58:34 +0200 Subject: [PATCH] network: don't use reinterpret_cast in GetAvailableNetworkInterfaces --- src/core/network/network_interface.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/core/network/network_interface.cpp b/src/core/network/network_interface.cpp index e9060f13fd..75f4dc54fb 100644 --- a/src/core/network/network_interface.cpp +++ b/src/core/network/network_interface.cpp @@ -23,20 +23,17 @@ namespace Network { #ifdef _WIN32 std::vector GetAvailableNetworkInterfaces() { - std::vector adapter_addresses_raw; - auto adapter_addresses = reinterpret_cast(adapter_addresses_raw.data()); + std::vector adapter_addresses; DWORD ret = ERROR_BUFFER_OVERFLOW; DWORD buf_size = 0; // retry up to 5 times for (int i = 0; i < 5 && ret == ERROR_BUFFER_OVERFLOW; i++) { ret = GetAdaptersAddresses(AF_INET, GAA_FLAG_SKIP_MULTICAST | GAA_FLAG_SKIP_DNS_SERVER, - nullptr, adapter_addresses, &buf_size); + nullptr, adapter_addresses.data(), &buf_size); if (ret == ERROR_BUFFER_OVERFLOW) { - adapter_addresses_raw.resize(buf_size); - adapter_addresses = - reinterpret_cast(adapter_addresses_raw.data()); + adapter_addresses.resize((buf_size / sizeof(IP_ADAPTER_ADDRESSES)) + 1); } else { break; } @@ -45,7 +42,7 @@ std::vector GetAvailableNetworkInterfaces() { if (ret == NO_ERROR) { std::vector result; - for (auto current_address = adapter_addresses; current_address != nullptr; + for (auto current_address = adapter_addresses.data(); current_address != nullptr; current_address = current_address->Next) { if (current_address->FirstUnicastAddress == nullptr || current_address->FirstUnicastAddress->Address.lpSockaddr == nullptr) {