diff options
Diffstat (limited to 'src/common/IPLocation/IPLocation.cpp')
-rw-r--r-- | src/common/IPLocation/IPLocation.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/common/IPLocation/IPLocation.cpp b/src/common/IPLocation/IPLocation.cpp index a1717420eb4..2dfd025fc7e 100644 --- a/src/common/IPLocation/IPLocation.cpp +++ b/src/common/IPLocation/IPLocation.cpp @@ -16,11 +16,12 @@ */ #include "IPLocation.h" -#include "Common.h" #include "Config.h" #include "Errors.h" #include "IpAddress.h" #include "Log.h" +#include "StringConvert.h" +#include "Util.h" #include <fstream> #include <iostream> @@ -83,9 +84,17 @@ void IpLocationStore::Load() countryName.erase(std::remove(countryName.begin(), countryName.end(), '"'), countryName.end()); // Convert country code to lowercase - std::transform(countryCode.begin(), countryCode.end(), countryCode.begin(), ::tolower); + strToLower(countryCode); - _ipLocationStore.emplace_back(uint32(atoul(ipFrom.c_str())), uint32(atoul(ipTo.c_str())), std::move(countryCode), std::move(countryName)); + Optional<uint32> from = Trinity::StringTo<uint32>(ipFrom); + if (!from) + continue; + + Optional<uint32> to = Trinity::StringTo<uint32>(ipTo); + if (!to) + continue; + + _ipLocationStore.emplace_back(*from, *to, std::move(countryCode), std::move(countryName)); } std::sort(_ipLocationStore.begin(), _ipLocationStore.end(), [](IpLocationRecord const& a, IpLocationRecord const& b) { return a.IpFrom < b.IpFrom; }); |