From 79764430d820bec44ff69ecca42bffb2700dcaea Mon Sep 17 00:00:00 2001 From: TheLastRar Date: Sat, 24 Dec 2022 17:29:59 +0000 Subject: [PATCH] DEV9: Fix out_of_range exception with automatic gateway --- pcsx2/DEV9/AdapterUtils.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pcsx2/DEV9/AdapterUtils.cpp b/pcsx2/DEV9/AdapterUtils.cpp index 16b88aa6b3..f34d3bf952 100644 --- a/pcsx2/DEV9/AdapterUtils.cpp +++ b/pcsx2/DEV9/AdapterUtils.cpp @@ -334,8 +334,11 @@ std::vector AdapterUtils::GetGateways(ifaddrs* adapter) { std::vector 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(std::stoul(gatewayIPHex, 0, 16)); + // Skip device routes without valid NextHop IP address. if (addressValue != 0) { IP_Address gwIP = *(IP_Address*)&addressValue;