mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-15 20:46:37 +08:00
cm/string_view: Prevent find access past string end
This commit is contained in:
@@ -85,11 +85,14 @@ int string_view::compare(size_type pos1, size_type count1, char const* s,
|
|||||||
string_view::size_type string_view::find(string_view v,
|
string_view::size_type string_view::find(string_view v,
|
||||||
size_type pos) const noexcept
|
size_type pos) const noexcept
|
||||||
{
|
{
|
||||||
|
if (pos < size_) {
|
||||||
for (; pos + v.size_ <= size_; ++pos) {
|
for (; pos + v.size_ <= size_; ++pos) {
|
||||||
if (std::char_traits<char>::compare(data_ + pos, v.data_, v.size_) == 0) {
|
if (std::char_traits<char>::compare(data_ + pos, v.data_, v.size_) ==
|
||||||
|
0) {
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return npos;
|
return npos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user