DEV9: Fix out_of_range exception with automatic gateway

This commit is contained in:
TheLastRar 2022-12-24 17:29:59 +00:00 committed by refractionpcsx2
parent 51107ee9dd
commit 79764430d8
1 changed files with 5 additions and 2 deletions

View File

@ -334,8 +334,11 @@ std::vector<IP_Address> AdapterUtils::GetGateways(ifaddrs* adapter)
{
std::vector<std::string_view> split = StringUtil::SplitString(line, '\t', true);
std::string gatewayIPHex{split[2]};
int addressValue = std::stoi(gatewayIPHex, 0, 16);
//Skip device routes without valid NextHop IP address
// stoi assumes hex values are unsigned, but tries to store it in a signed int,
// this results in a std::out_of_range exception for addresses ending in a number > 128.
// We don't have a stoui for (unsigned int), so instead use stoul for (unsigned long).
u32 addressValue = static_cast<u32>(std::stoul(gatewayIPHex, 0, 16));
// Skip device routes without valid NextHop IP address.
if (addressValue != 0)
{
IP_Address gwIP = *(IP_Address*)&addressValue;