diff options
author | Chris Robinson <[email protected]> | 2021-01-08 18:51:25 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2021-01-08 18:51:25 -0800 |
commit | 537fd6d0a15fda5f4b6ed3f767aa9bf6f15caa21 (patch) | |
tree | 7ef173445d5f57d5960adebeb236827f5b8820fb /core/cpu_caps.cpp | |
parent | 1f24f5caa1c5370b942938d714cf203f5564de7c (diff) |
Avoid dereferencing the end iterator
Diffstat (limited to 'core/cpu_caps.cpp')
-rw-r--r-- | core/cpu_caps.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/core/cpu_caps.cpp b/core/cpu_caps.cpp index dc992663..8211b331 100644 --- a/core/cpu_caps.cpp +++ b/core/cpu_caps.cpp @@ -69,11 +69,11 @@ al::optional<CPUInfo> GetCPUInfo() ret.mVendor.append(reinterpret_cast<char*>(&cpuregs[3]), 4); ret.mVendor.append(reinterpret_cast<char*>(&cpuregs[2]), 4); auto iter_end = std::remove(ret.mVendor.begin(), ret.mVendor.end(), '\0'); - while(iter_end != ret.mVendor.begin() && std::isspace(*iter_end)) - --iter_end; iter_end = std::unique(ret.mVendor.begin(), iter_end, [](auto&& c0, auto&& c1) { return std::isspace(c0) && std::isspace(c1); }); ret.mVendor.erase(iter_end, ret.mVendor.end()); + if(!ret.mVendor.empty() && std::isspace(ret.mVendor.back())) + ret.mVendor.pop_back(); if(!ret.mVendor.empty() && std::isspace(ret.mVendor.front())) ret.mVendor.erase(ret.mVendor.begin()); @@ -86,11 +86,11 @@ al::optional<CPUInfo> GetCPUInfo() cpuregs = get_cpuid(0x80000004); ret.mName.append(reinterpret_cast<char*>(cpuregs.data()), 16); iter_end = std::remove(ret.mName.begin(), ret.mName.end(), '\0'); - while(iter_end != ret.mName.begin() && std::isspace(*iter_end)) - --iter_end; iter_end = std::unique(ret.mName.begin(), iter_end, [](auto&& c0, auto&& c1) { return std::isspace(c0) && std::isspace(c1); }); ret.mName.erase(iter_end, ret.mName.end()); + if(!ret.mName.empty() && std::isspace(ret.mName.back())) + ret.mName.pop_back(); if(!ret.mName.empty() && std::isspace(ret.mName.front())) ret.mName.erase(ret.mName.begin()); } |