From 0a26c08004aeced08599625aee59391381403185 Mon Sep 17 00:00:00 2001 From: Sergiu Deitsch Date: Thu, 11 Sep 2025 15:05:53 +0200 Subject: [PATCH] cm/string_view: Prevent find access past string end --- Utilities/std/cm/bits/string_view.cxx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Utilities/std/cm/bits/string_view.cxx b/Utilities/std/cm/bits/string_view.cxx index bd5fb605f0..4a18e2fa14 100644 --- a/Utilities/std/cm/bits/string_view.cxx +++ b/Utilities/std/cm/bits/string_view.cxx @@ -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::compare(data_ + pos, v.data_, v.size_) == 0) { - return pos; + if (pos < size_) { + for (; pos + v.size_ <= size_; ++pos) { + if (std::char_traits::compare(data_ + pos, v.data_, v.size_) == + 0) { + return pos; + } } } return npos;