1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-15 03:48:02 +08:00

cm/string_view: Prevent find access past string end

This commit is contained in:
Sergiu Deitsch
2025-09-11 15:05:53 +02:00
parent 63328f01f8
commit 0a26c08004

View File

@@ -85,9 +85,12 @@ int string_view::compare(size_type pos1, size_type count1, char const* s,
string_view::size_type string_view::find(string_view v,
size_type pos) const noexcept
{
for (; pos + v.size_ <= size_; ++pos) {
if (std::char_traits<char>::compare(data_ + pos, v.data_, v.size_) == 0) {
return pos;
if (pos < size_) {
for (; pos + v.size_ <= size_; ++pos) {
if (std::char_traits<char>::compare(data_ + pos, v.data_, v.size_) ==
0) {
return pos;
}
}
}
return npos;