Skip to content

Commit abd892a

Browse files
committed
fix: some Windows APIs return error codes directly without using GetLastError
1 parent f01dbf9 commit abd892a

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

src/os/net.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ std::expected<std::map<std::string, zero::os::net::Interface>, std::error_code>
7878
break;
7979

8080
if (result != ERROR_BUFFER_OVERFLOW)
81-
return std::unexpected{std::error_code{static_cast<int>(GetLastError()), std::system_category()}};
81+
return std::unexpected{std::error_code{static_cast<int>(result), std::system_category()}};
8282

8383
buffer = std::make_unique<std::byte[]>(size);
8484
}
@@ -95,8 +95,9 @@ std::expected<std::map<std::string, zero::os::net::Interface>, std::error_code>
9595

9696
std::array<WCHAR, NDIS_IF_MAX_STRING_SIZE + 1> buf{};
9797

98-
if (ConvertInterfaceLuidToNameW(&adapter->Luid, buf.data(), buf.size()) != ERROR_SUCCESS)
99-
return std::unexpected{std::error_code{static_cast<int>(GetLastError()), std::system_category()}};
98+
if (const auto result = ConvertInterfaceLuidToNameW(&adapter->Luid, buf.data(), buf.size());
99+
result != ERROR_SUCCESS)
100+
return std::unexpected{std::error_code{static_cast<int>(result), std::system_category()}};
100101

101102
const auto name = strings::encode(buf.data());
102103
Z_EXPECT(name);

0 commit comments

Comments
 (0)